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
847
votes
11 answers

What are the differences between the urllib, urllib2, urllib3 and requests module?

In Python, what are the differences between the urllib, urllib2, urllib3 and requests modules? Why are there three? They seem to do the same thing...
Paul Biggar
  • 24,430
  • 19
  • 91
  • 139
789
votes
7 answers

How to POST JSON data with Python Requests?

I need to POST a JSON from a client to a server. I'm using Python 2.7.1 and simplejson. The client is using Requests. The server is CherryPy. I can GET a hard-coded JSON from the server (code not shown), but when I try to POST a JSON to the server,…
Charles R
  • 13,781
  • 6
  • 18
  • 18
682
votes
27 answers

ImportError: No module named requests

Whenever I try to import requests, I get an error saying No module Named requests. import requests The error I get: File "ex2.py", line 1, in import requests ImportError: No module named requests
user2476540
  • 6,965
  • 4
  • 11
  • 9
507
votes
3 answers

Correct way to try/except using Python requests module?

try: r = requests.get(url, params={'s': thing}) except requests.ConnectionError, e: print e #should I also sys.exit(1) after this? Is this correct? Is there a better way to structure this? Will this cover all my bases?
John Smith
  • 9,380
  • 16
  • 43
  • 49
466
votes
6 answers

Download large file in python with requests

Requests is a really nice library. I'd like to use it for downloading big files (>1GB). The problem is it's not possible to keep whole file in memory; I need to read it in chunks. And this is a problem with the following code: import requests def…
Roman Podlinov
  • 19,179
  • 7
  • 37
  • 56
424
votes
14 answers

How to download image using requests

I'm trying to download and save an image from the web using python's requests module. Here is the (working) code I used: img = urllib2.urlopen(settings.STATICMAP_URL.format(**data)) with open(path, 'w') as f: f.write(img.read()) Here is the new…
shkschneider
  • 16,338
  • 12
  • 55
  • 107
400
votes
24 answers

Python Requests throwing SSLError

I'm working on a simple script that involves CAS, jspring security check, redirection, etc. I would like to use Kenneth Reitz's python requests because it's a great piece of work! However, CAS requires getting validated via SSL so I have to get…
TedBurrows
  • 4,261
  • 4
  • 14
  • 10
392
votes
12 answers

How do I disable log messages from the Requests library?

By default, the Requests python library writes log messages to the console, along the lines of: Starting new HTTP connection (1): example.com http://example.com:80 "GET / HTTP/1.1" 200 606 I'm usually not interested in these messages, and would…
aknuds1
  • 57,609
  • 57
  • 177
  • 299
314
votes
5 answers

How can I see the entire HTTP request that's being sent by my Python application?

In my case, I'm using the requests library to call PayPal's API over HTTPS. Unfortunately, I'm getting an error from PayPal, and PayPal support cannot figure out what the error is or what's causing it. They want me to "Please provide the entire…
Chris B.
  • 71,470
  • 23
  • 89
  • 130
313
votes
2 answers

What's the best way to parse a JSON response from the requests library?

I'm using the python requests module to send a RESTful GET to a server, for which I get a response in JSON. The JSON response is basically just a list of lists. What's the best way to coerce the response to a native Python object so I can either…
felix001
  • 12,330
  • 27
  • 79
  • 103
284
votes
6 answers

How do I disable the security certificate check in Python requests

I am using import requests requests.post(url='https://foo.com', data={'bar':'baz'}) but I get a request.exceptions.SSLError. The website has an expired certficate, but I am not sending sensitive data, so it doesn't matter to me. I would imagine…
Paul Draper
  • 64,883
  • 37
  • 172
  • 246
263
votes
11 answers

How to send a "multipart/form-data" with requests in python?

How to send a multipart/form-data with requests in python? How to send a file, I understand, but how to send the form data by this method can not understand.
agrynchuk
  • 3,399
  • 3
  • 15
  • 17
262
votes
2 answers

Python Requests - No connection adapters

I'm using the Requests: HTTP for Humans library and I got this weird error and I don't know what is mean. No connection adapters were found for '192.168.1.61:8080/api/call' Anybody has an idea?
Azd325
  • 4,526
  • 5
  • 31
  • 50
257
votes
2 answers

Sending "User-agent" using Requests library in Python

I want to send a value for "User-agent" while requesting a webpage using Python Requests. I am not sure is if it is okay to send this as a part of the header, as in the code below: debug = {'verbose': sys.stderr} user_agent = {'User-agent':…
user1289853
248
votes
9 answers

Python requests - print entire http request (raw)?

While using the requests module, is there any way to print the raw HTTP request? I don't want just the headers, I want the request line, headers, and content printout. Is it possible to see what ultimately is constructed from HTTP request?
huggie
  • 15,393
  • 21
  • 74
  • 128
1
2 3
99 100