0

I have the following scenario:

  • I have logged in successful with with mechanize.Browser():
url_login = "http://my_login_page.com/login"
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders =  [
    (
        "User-agent",
        "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1",
    )
]

resp = br.open(url_login)

br.select_form(nr=0)
br.form["username"] = "user"
br.form["password"] = "SUPERSECRETPASSWORD"
br.submit()
  • I switched pages:
url_api= "http://my_login_page.com/account/user"
resp = br.open(url_api)
  • I roughly analyzed responded HTML and besides of missing assets the page looked fine
  • Next I want to create a POST request with the provided XSRF cookies saved in the cookiejar of the browser. But here is the point I am failing.
new_headers = {"Content-Type": "application/json"}

params = {"errors": [], "name": "TEST_CODE", "scopes": []}
data = urllib.parse.urlencode(params)

request = mechanize.Request(
    "http://my_login_page.com/oauth/personal-access-tokens"
)

resp = br.open(request, data=data)

I tried the answers from Sending a POST with mechanize and requests. , with no success.

I've tried the following: https://qxf2.com/blog/python-mechanize-the-missing-manual/, also no success.

I always get a HTML response back (Quote that my session has expired) instead of the expected json response body. I have the gut feeling that I am just before the solution, but I do not see it.

MaKaNu
  • 762
  • 8
  • 25

0 Answers0