3

I am trying to download an export from an app automatically with python. Here is my code:

export_url = 'https://....'
payload = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
r = requests.post(export_url, data=payload)
print(r)

the response is 200 but the file is missing somehow what is wrong?

edit:

this is my whole code:

import requests

URL = 'homepage_after_login'
LOGIN_URL = 'loginpage'

session = requests.session()

username = 'uname'
password = 'pass'
loginformtype = "value"
submit = "Sign+in"

login_data = {'username'        : username,
              'password'        : password,
              'login-form-type' : loginformtype,
              'submit'          : submit}

session.post(LOGIN_URL, data=login_data)

req = session.get(URL)

export_url = 'https://....'
payload = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
r = requests.post(export_url, data=payload)
print(r)

possibily it ignores the login part?

gyld
  • 31
  • 4
  • 1
    Possible duplicate of [How to download image using requests](http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests) – Andrii Rusanov Mar 02 '16 at 12:32
  • your code only gets the content in memory but never writes it to a file – maazza Mar 02 '16 at 12:35

1 Answers1

2

Perhaps you should take a look at the documentation.

When you print r, you get the status code. (Well, not exactly, but the printed number is the status code.)

What you probably want to use is r.text:

text

Content of the response, in unicode.

If Response.encoding is None, encoding will be guessed using chardet.

The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set r.encoding appropriately before accessing this property.

Or r.content:

content

Content of the response, in bytes.

Yuriko
  • 576
  • 3
  • 14