0

I want to do a post request on a website with Python. Here is the code

with requests.Session( ) as s:
    s.get(url)
    logdata = {'login': 'xxx', 'password': 'xxx'}

    s.post(url,data=log_data)
    r=s.get(url)

I remembered these lines were enough to open the url with the good login data but it seems not. Does someone know why?

EqElahin
  • 1
  • 1

1 Answers1

0

You are doing a GET and not a POST in your code - see https://stackoverflow.com/a/15794896/2590615 for POST example.

Also your variable r will only contain the server response as a string.

If you want to open your web browser with URL you must call your browser application from your code and give an URL as parameter - I do not know if it possible to apply post parameters in this way (I do not think so) .

So I would suggest to

  • change your code and POST your wanted data and use still r to hold server response
  • write content of r into a file (e.g. ~/result-post.html when response is HTML)
  • call your browser application with file location (e.g. firefox ~/result-post.html) - or process the output programmatically
de-jcup
  • 1,402
  • 12
  • 27