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.
21751 questions
178
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
  • 14,859
  • 8
  • 20
  • 11
177
votes
11 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
  • 16,701
  • 27
  • 128
  • 231
173
votes
8 answers

Python Requests and persistent sessions

I am using the requests module. I have figured out how to submit data to a login form on a website and retrieve the session key, but I can't see an obvious way to use this session key in subsequent requests. Can someone fill in the ellipsis in the…
ChrisGuest
  • 3,398
  • 4
  • 32
  • 53
172
votes
1 answer

zsh: no matches found: requests[security]

I am trying to run a python urllib2 script and getting this error: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For…
Kristen
  • 1,731
  • 2
  • 11
  • 7
162
votes
6 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
  • 2,267
  • 5
  • 22
  • 21
158
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
  • 41,341
  • 63
  • 198
  • 344
157
votes
3 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
  • 5,274
  • 12
  • 41
  • 59
154
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
153
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
  • 2,505
  • 6
  • 22
  • 27
144
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
  • 9,483
  • 12
  • 38
  • 39
142
votes
3 answers

How to fix "403 Forbidden" errors when calling APIs using Python requests?

I needed to parse a site, but I got a 403 Forbidden error. Here is the code: url = 'http://worldagnetwork.com/' result = requests.get(url) print(result.content.decode()) The output is: 403 Forbidden
142
votes
3 answers

Difference between data and json parameters in Python Requests package

What is the difference between the data and json parameters in the Python Requests package? It is unclear from the documentation. Does this code: import requests import json d = {'a': 1} response = requests.post(url, data=json.dumps(d)) ( note that…
user1507844
  • 5,973
  • 10
  • 38
  • 55
141
votes
8 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
  • 2,097
  • 5
  • 24
  • 30
137
votes
26 answers

Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."

I'm using requests in Python3 on Windows via Pycharm, and I'm receiving a "SSL module is 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…
Frank Drin
  • 1,613
  • 2
  • 13
  • 18
137
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.example", proxies = {'http': '222.255.169.74:8080'}, ) print(r.ok) What could be the…
Nawaz
  • 353,942
  • 115
  • 666
  • 851