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
1049
votes
10 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
  • 17,989
  • 6
  • 20
  • 18
1005
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
  • 27,579
  • 21
  • 99
  • 152
909
votes
34 answers

ImportError: No module named requests

I tried importing requests: import requests But I get an error: ImportError: No module named requests
user2476540
  • 9,265
  • 4
  • 15
  • 9
716
votes
4 answers

Correct way to try/except using Python requests module?

try: r = requests.get(url, params={'s': thing}) except requests.ConnectionError, e: print(e) Is this correct? Is there a better way to structure this? Will this cover all my bases?
John Smith
  • 11,678
  • 17
  • 46
  • 51
602
votes
9 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
  • 23,806
  • 7
  • 41
  • 60
512
votes
29 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
  • 5,401
  • 4
  • 16
  • 10
503
votes
18 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
  • 17,833
  • 13
  • 59
  • 112
471
votes
11 answers

How do I disable the security certificate check in Python requests

I am using import requests requests.post(url='https://foo.example', 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
  • 78,542
  • 46
  • 206
  • 285
441
votes
13 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
  • 65,625
  • 67
  • 195
  • 317
400
votes
3 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
  • 15,341
  • 32
  • 94
  • 121
391
votes
9 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.
  • 85,731
  • 25
  • 98
  • 139
369
votes
14 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
  • 4,597
  • 3
  • 17
  • 17
365
votes
5 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
  • 5,752
  • 5
  • 34
  • 57
343
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
  • 17,587
  • 27
  • 82
  • 139
338
votes
3 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
1
2 3
99 100