Questions tagged [python-requests]

USE ONLY FOR THE PYTHON REQUESTS LIBRARY. Requests is a full-featured Python HTTP library with an easy-to-use, logical API.

Official web site

Requests is an HTTP library written in Python under the Apache2 license.

It's meant to simplify HTTP 1.1 related tasks with several functionality out of the box. For example, there’s no need to manually add query strings to your URLs or to form-encode your POST data. Keep-alive and HTTP connection pooling are 100% automatic.

Features:

  • International Domains and URLs
  • Keep-Alive & Connection Pooling
  • Sessions with Cookie Persistence
  • Browser-style SSL Verification
  • Automatic Content Decoding
  • Basic/Digest Authentication
  • Elegant Key/Value Cookies
  • Automatic Decompression
  • Unicode Response Bodies
  • Multipart File Uploads
  • Streaming Downloads
  • Connection Timeouts
  • .netrc support
  • Chunked Requests
  • Python 2.6—3.8
  • Thread-safe.
16852 questions
130
votes
2 answers

Adding headers to requests module

Earlier I used httplib module to add a header in the request. Now I am trying the same thing with the requests module. This is the python request module I am using: http://pypi.python.org/pypi/requests How can I add a header to request.post() and…
discky
  • 13,001
  • 7
  • 18
  • 11
121
votes
3 answers

How to send cookies in a post request with the Python Requests library?

I'm trying to use the Requests library to send cookies with a post request, but I'm not sure how to actually set up the cookies based on its documentation. The script is for use on Wikipedia, and the cookie(s) that need to be sent are of this…
Ricardo Altamirano
  • 12,617
  • 20
  • 67
  • 104
121
votes
5 answers

Python Requests library redirect new url

I've been looking through the Python Requests documentation but I cannot see any functionality for what I am trying to achieve. In my script I am setting allow_redirects=True. I would like to know if the page has been redirected to something else,…
Daniel Pilch
  • 1,807
  • 2
  • 20
  • 29
120
votes
2 answers

Python Requests package: Handling xml response

I like very much the requests package and its comfortable way to handle JSON responses. Unfortunately, I did not understand if I can also process XML responses. Has anybody experience how to handle XML responses with the requests package? Is it…
Andy
  • 7,399
  • 10
  • 33
  • 37
112
votes
8 answers

Log all requests from the python-requests module

I am using python Requests. I need to debug some OAuth activity, and for that I would like it to log all requests being performed. I could get this information with ngrep, but unfortunately it is not possible to grep https connections (which are…
blueFast
  • 33,335
  • 48
  • 165
  • 292
109
votes
9 answers

Python requests library how to pass Authorization header with single token

I have a request URI and a token. If I use: curl -s "" -H "Authorization: TOK:" etc., I get a 200 and view the corresponding JSON data. So, I installed requests and when I attempt to access this resource I get a 403 probably…
user1552586
105
votes
6 answers

How to "log in" to a website using Python's Requests module?

I am trying to post a request to log in to a website using the Requests module in Python but its not really working. I'm new to this...so I can't figure out if I should make my Username and Password cookies or some type of HTTP authorization thing I…
Marcus Johnson
  • 1,923
  • 5
  • 18
  • 26
101
votes
6 answers

Why doesn't requests.get() return? What is the default timeout that requests.get() uses?

In my script, requests.get never returns: import requests print ("requesting..") # This call never returns! r = requests.get( "http://www.some-site.com", proxies = {'http': '222.255.169.74:8080'}, ) print(r.ok) What could be the possible…
Nawaz
  • 327,095
  • 105
  • 629
  • 812
98
votes
25 answers

Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website

Using requests in Python3 Windows via Pycharm, and receiving SSL Module Not Available Error I've spent hours trying to figure out what could be causing this. I've reinstalled Anaconda, and I am completely stuck. When running the following def…
Frank Drin
  • 1,163
  • 1
  • 6
  • 16
98
votes
7 answers

How to get Python requests to trust a self signed SSL certificate?

import requests data = {'foo':'bar'} url = 'https://foo.com/bar' r = requests.post(url, data=data) If the URL uses a self signed certificate, this fails with requests.exceptions.SSLError: [Errno 1] _ssl.c:507: error:14090086:SSL…
Matthew Moisen
  • 12,418
  • 23
  • 90
  • 195
93
votes
1 answer

Access Lovoo API using Python

I am hoping to make use of the lovoo API, but don't really know how to start. After running Charles proxy and looking at the traffic, I have come to the following conclusion: First a GET to https://api.lovoo.com/oauth/requestToken? is sent as soon…
rhillhouse
  • 1,551
  • 1
  • 13
  • 28
93
votes
6 answers

Download and save PDF file with Python requests module

I am trying to download a PDF file from a website and save it to disk. My attempts either fail with encoding errors or result in blank PDFs. In [1]: import requests In [2]: url = 'http://www.hrecos.org//images/Data/forweb/HRTVBSH.Metadata.pdf' In…
Jim
  • 1,300
  • 1
  • 11
  • 17
93
votes
3 answers

How do I read a response from Python Requests?

I have two Python scripts. One uses the Urllib2 library and one uses the Requests library. I have found Requests easier to implement, but I can't find an equivalent for urlib2's read() function. For example: ... response = url.urlopen(req) print…
Oli
  • 1,547
  • 4
  • 17
  • 21
87
votes
2 answers

How to extract HTTP response body from a Python requests call?

I'm using the Python requests library. I'm trying to figure out how to extract the actual HTML body from a response. The code looks a bit like this: r = requests.get(...) print r.content This should indeed print lots of content, but instead prints…
Stephen Gross
  • 4,294
  • 9
  • 35
  • 55
87
votes
9 answers

How to make python Requests work via socks proxy

I'm using the great Requests library in my Python script: import requests r = requests.get("some-site.com") print r.text I would like to use socks proxy. But Requests only supports HTTP proxy now. How can I do that?
lithuak
  • 5,409
  • 8
  • 38
  • 52