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
85
votes
1 answer

Sending SOAP request using Python Requests

Is it possible to use Python's requests library to send a SOAP request?
Deepankar Bajpeyi
  • 5,036
  • 10
  • 37
  • 60
81
votes
2 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 we…
user1507844
  • 4,345
  • 7
  • 32
  • 53
80
votes
8 answers

ImportError: No module named 'Queue'

I am trying to import requests module, but I got this error my python version is 3.4 running on ubuntu 14.04 >>> import requests Traceback (most recent call last): File…
Ali Faki
  • 3,311
  • 3
  • 13
  • 23
78
votes
3 answers

Python requests. 403 Forbidden

I needed to parse a site, but i got an error 403 Forbidden. Here is a code: url = 'http://worldagnetwork.com/' result = requests.get(url) print(result.content.decode()) Its output: 403 Forbidden
75
votes
4 answers

How to send an array using requests.post (Python)? "Value Error: Too many values to unpack"

I'm trying to send an array(list) of requests to the WheniWork API using requests.post, and I keep getting one of two errors. When I send the list as a list, I get an unpacking error, and when I send it as a string, I get an error asking me to…
Bobby Battista
  • 1,645
  • 2
  • 13
  • 25
74
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
  • 743
  • 1
  • 5
  • 6
72
votes
5 answers

Unit testing a python app that uses the requests library

I am writing an application that performs REST operations using Kenneth Reitz's requests library and I'm struggling to find a nice way to unit test these applications, because requests provides its methods via module-level methods. What I want is…
Chris R
  • 16,477
  • 22
  • 97
  • 163
72
votes
3 answers

How to use cookies in Python Requests

I am trying to login to a page and access another link in the page. payload={'username'=,'password'=} with session() as s: r = c.post(, data=payload) print r print r.content This is giving me a "405 Not Allowed"…
user1474157
  • 757
  • 1
  • 7
  • 11
72
votes
2 answers

python requests get cookies

x = requests.post(url, data=data) print x.cookies I used the requests library to get some cookies from a website, but I can only get the cookies from the Response, how to get the cookies from the Request? Thanks!
Danfi
  • 872
  • 1
  • 9
  • 14
70
votes
1 answer

Python requests speed up using keep-alive

In the HTTP protocol you can send many requests in one socket using keep-alive and then receive the response from server at once, so that will significantly speed up whole process. Is there any way to do this in python requests lib? Or are there any…
PaulOverflow
  • 871
  • 1
  • 8
  • 11
70
votes
3 answers

How to receive json data using HTTP POST request in Django 1.6?

I am learning Django 1.6. I want to post some JSON using HTTP POST request and I am using Django for this task for learning. I tried to use request.POST['data'], request.raw_post_data, request.body but none are working for me. my views.py is …
Alok Singh Mahor
  • 5,210
  • 5
  • 36
  • 53
68
votes
9 answers

Python: download a file from an FTP server

I'm trying to download some public data files. I screenscrape to get the links to the files, which all look something like this: ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/nhanes/2001-2002/L28POC_B.xpt I can't find any documentation on the…
user1507455
  • 863
  • 2
  • 8
  • 10
64
votes
6 answers

How to implement retry mechanism into python requests library?

I would like to add a retry mechanism to python request library, so scripts that are using it will retry for non fatal errors. At this moment I do consider three kind of errors to be recoverable: HTTP return codes 502, 503, 504 host not found (less…
sorin
  • 137,198
  • 150
  • 472
  • 707
63
votes
6 answers

using requests with TLS doesn't give SNI support

I'm using requests to communicate with a django app but When I try requests.get('https://mysite.com', verify=True) I get the error: hostname 'mysite.com' doesn't match either of '*.myhost.com', 'myhost.com' However, when I look at the browser, or…
Massagran
  • 1,681
  • 1
  • 18
  • 27
62
votes
2 answers

How to measure server response time for Python requests POST-request?

I create requests POST-requests like this, where I specify timeout threshold: response = requests.post(url, data=post_fields, timeout=timeout) However, to determine a "good" threshold value, I would like to benchmark the server response time in…
Shuzheng
  • 7,974
  • 8
  • 48
  • 112