Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadRequestKeyError when attempting to retrieve fb access token #131

Open
Klexus1 opened this issue Mar 20, 2021 · 4 comments
Open

BadRequestKeyError when attempting to retrieve fb access token #131

Klexus1 opened this issue Mar 20, 2021 · 4 comments

Comments

@Klexus1
Copy link

Klexus1 commented Mar 20, 2021

Error:
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

To replicate the behaviour:
Clone the repository (as of 20 . 3. 2021)
Install requirements (with Werkzeug==0.16.1)
Enter your credentials in tinder_config_ex.py

Run.

Full traceback:

Traceback (most recent call last):
  File "C:/test-projekty/tinder-api/Tinder/tinder_config_ex.py", line 5, in <module>
    fb_access_token = fb_auth_token.get_fb_access_token(fb_username, fb_password)
  File "C:\test-projekty\tinder-api\Tinder\fb_auth_token.py", line 16, in get_fb_access_token
    f["pass"] = password
  File "C:\test-projekty\tinder-api\Tinder\tinderenv\lib\site-packages\robobrowser\forms\form.py", line 216, in __setitem__
    self.fields[key].value = value
  File "C:\test-projekty\tinder-api\Tinder\tinderenv\lib\site-packages\werkzeug\datastructures.py", line 795, in __getitem__
    raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Process finished with exit code 1

The program fails on s.open(FB_AUTH) line 14, fb_auth_token.py

Note: the FB_AUTH is a valid url. Tried in browser and works as expected.

@aspirez4
Copy link

Change get_fb_access_token function to this

def get_fb_access_token(email, password):
    s = robobrowser.RoboBrowser(user_agent=MOBILE_USER_AGENT, parser="lxml")
    s.open(FB_AUTH)
    f = s.get_form()
    s.submit_form(f)
    f = s.get_form()
    f["pass"] = password
    f["email"] = email
    s.submit_form(f)
    f = s.get_form()
    try:
        s.submit_form(f, submit=f.submit_fields['__CONFIRM__'])
        access_token = re.search(
            r"access_token=([\w\d]+)", s.response.content.decode()).groups()[0]
        return access_token
    except requests.exceptions.InvalidSchema as browserAddress:
        access_token = re.search(
            r"access_token=([\w\d]+)",str(browserAddress)).groups()[0]
        return access_token
    except Exception as ex:
        print("access token could not be retrieved. Check your username and password.")
        print("Official error: %s" % ex)
        return {"error": "access token could not be retrieved. Check your username and password."}

@Edvards79
Copy link

Change MOBILE_USER_AGENT variable to Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; SCH-I535 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30. The old one seems to be outdated for facebook and it shows error message instead of the login form.

@NorrisPau
Copy link

Did you find a fix after all @jsdjsd ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants