meta-ai-api
meta-ai-api copied to clipboard
Error on first run
I passed the credentials as mentioned in the documentation and encountered the following error. I'm hosting this on the us-central1-c region of Google Cloud.
Traceback (most recent call last):
File "/home/ubuntu/test.py", line 11, in <module>
ai = MetaAI(fb_email="[email protected]", fb_password="xxxxxxx")
File "/home/ubuntu/.venv/lib/python3.10/site-packages/meta_ai_api/main.py", line 50, in __init__
self.cookies = self.get_cookies()
File "/home/ubuntu/.venv/lib/python3.10/site-packages/meta_ai_api/main.py", line 335, in get_cookies
fb_session = get_fb_session(self.fb_email, self.fb_password)
File "/home/ubuntu/.venv/lib/python3.10/site-packages/meta_ai_api/utils.py", line 157, in get_fb_session
"xs": session.cookies["xs"],
File "/home/ubuntu/.venv/lib/python3.10/site-packages/requests/cookies.py", line 334, in __getitem__
return self._find_no_duplicates(name)
File "/home/ubuntu/.venv/lib/python3.10/site-packages/requests/cookies.py", line 413, in _find_no_duplicates
raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}")
KeyError: "name='xs', domain=None, path=None"
Please assist.
I tried to debug this issue and found the following:
- URL
https://mbasic.facebook.com/login/returntemporarily blocked. - Which leads to not getting the hidden field values.
- Also, I think it prevents from executing
https://mbasic.facebook.com/login/device-based/regular/login/?refsrc=deprecated&lwv=100 - Also, the response cookies are not available in the
session.cookies.
Workaround:
- Manually login to the site using the URL
https://mbasic.facebook.com/login/(The block page was not showing) from the Chrome browser - Copy the values of the cookies and hardcode them in the
utils.py - The values to be hard coded in
def get_fb_session(...):
lsd = ""
jazoest = ""
li = ""
m_ts = ""
datr = ""
sb = ""
xs = ""
fr = ""
c_user = ""
The above workaround works, but the only problem is having to manually set those values.
@Strvm Please check if these can be fixed.
Hi, the fact that you are running it on GCP is probably the issue. Meta is most likely blocking Datacenter IPs (to combat proxies). Either you host it somewhere else, or you can pass in your own proxies (while hoping they don't get blocked by Meta)
Hi, I spent some time today and fixed the login mechanism. Please upgrade to the latest version and try again on your end.
pip install meta-ai-api --upgrade
Example usage:
from meta_ai_api import MetaAI
ai = MetaAI(fb_email="EMAIL", fb_password="PASS")
resp = ai.prompt(message="Generate a flying corgi", stream=False)
print(resp)
Results to:
{'message': '\n', 'sources': [], 'media': [{'url': 'https://scontent-sjc3-1.xx.fbcdn.net/o1/v/t0/f1/m340/genai_m4_rva_prn_v3:upload_img_30150162_11_11_2024_15_38_53_839707_7210860893543658686.jpeg?_nc_ht=scontent-sjc3-1.xx.fbcdn.net&_nc_cat=105&ccb=9-4&oh=00_AYDdYcFmk3NE2fvIyRdfa1zplSNNUUKbdsKdY7nFtYMvjA&oe=67348AD2&_nc_sid=5b3566', 'type': 'IMAGE', 'prompt': 'a flying corgi'}, {'url': 'https://scontent-sjc3-1.xx.fbcdn.net/o1/v/t0/f1/m340/genai_m4_rva_ftw_v3:upload_img_80186289_11_11_2024_15_38_53_877200_5339600777371350444.jpeg?_nc_ht=scontent-sjc3-1.xx.fbcdn.net&_nc_cat=108&ccb=9-4&oh=00_AYCjw3uIocVsooGRlB6N27QYGQK93WlyaBCS5fhiShwTtA&oe=67346269&_nc_sid=5b3566', 'type': 'IMAGE', 'prompt': 'a flying corgi'}, {'url': 'https://scontent-sjc3-1.xx.fbcdn.net/o1/v/t0/f1/m340/genai_m4_rva_frc_v3:upload_img_1123599_11_11_2024_15_38_53_891297_2220685283103798415.jpeg?_nc_ht=scontent-sjc3-1.xx.fbcdn.net&_nc_cat=108&ccb=9-4&oh=00_AYAb7QbUyaTye_HxF0V1qz9yK5_1f-_cYSeERSKVs4h0OQ&oe=673479BE&_nc_sid=5b3566', 'type': 'IMAGE', 'prompt': 'a flying corgi'}, {'url': 'https://scontent-sjc3-1.xx.fbcdn.net/o1/v/t0/f1/m340/genai_m4_ncg_odn_v3:upload_img_438087_11_11_2024_15_38_53_922254_6380853868722563899.jpeg?_nc_ht=scontent-sjc3-1.xx.fbcdn.net&_nc_cat=108&ccb=9-4&oh=00_AYByFV4a_fjrPeHX8lcs2EyhGP4X4NQByFO7LYFh-I_63A&oe=67348268&_nc_sid=5b3566', 'type': 'IMAGE', 'prompt': 'a flying corgi'}]}
