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
36
votes
7 answers

Force requests to use IPv4 / IPv6

How to force the requests library to use a specific internet protocol version for a get request? Or can this be achieved better with another method in Python? I could but I do not want to use curl… Example to clarify purpose: import requests r =…
ominug
  • 1,422
  • 2
  • 12
  • 28
36
votes
4 answers

Ideal Chunk Size for python requests

Is there any guideline on selecting chunk size? I tried different chunk size but none of them give download speed comparable to browser or wget download speed here is snapshot of my code r = requests.get(url, headers = headers,stream=True) …
user3570335
36
votes
5 answers

Python: requests.exceptions.ConnectionError. Max retries exceeded with url

This is the script: import requests import json import urlparse from requests.adapters import HTTPAdapter s = requests.Session() s.mount('http://', HTTPAdapter(max_retries=1)) with open('proxies.txt') as proxies: for line in proxies: …
BigBoy1337
  • 4,735
  • 16
  • 70
  • 138
36
votes
3 answers

Python Requests - SSL error for client side cert

I'm calling a REST API with requests in python and so far have been successful when I set verify=False. Now, I have to use client side cert that I need to import for authentication and I'm getting this error everytime I'm using the cert (.pfx).…
onlyme
  • 457
  • 1
  • 5
  • 8
36
votes
5 answers

How to add a cookie to the cookiejar in python requests library

I am trying to add a cookie to an existing cookiejar using the python requests 1.2.3 library. Every time I add the new cookie, the data in the jar is munged for the new cookie. Keys missing, Values missing or matched to incorrect Keys. I'm not…
fat fantasma
  • 7,483
  • 15
  • 48
  • 66
36
votes
4 answers

What command to use instead of urllib.request.urlretrieve?

I'm currently writing a script that downloads a file from a URL import urllib.request urllib.request.urlretrieve(my_url, 'my_filename') The docs urllib.request.urlretrieve state: The following functions and classes are ported from the Python 2…
Marcus
  • 463
  • 1
  • 4
  • 5
35
votes
1 answer

pip install requests[security] vs pip install requests: Difference

I am using Ubuntu 14.04 (Trusty Tahr) with Python version 2.7.6. Today, when I created a new virtualenv and tried doing pip install requests, I got the error InsecurePlatformWarning. I resolved this issue by following the instructions in SSL…
Ymartin
  • 1,321
  • 1
  • 10
  • 24
35
votes
6 answers

Can't catch mocked exception because it doesn't inherit BaseException

I'm working on a project that involves connecting to a remote server, waiting for a response, and then performing actions based on that response. We catch a couple of different exceptions, and behave differently depending on which exception is…
Dan Oberlam
  • 2,435
  • 9
  • 36
  • 54
35
votes
2 answers

python requests - POST Multipart/form-data without filename in HTTP request

I am trying to replicate the following POST request using the requests module in python: POST /example/asdfas HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0 Accept:…
sornars
  • 1,139
  • 1
  • 8
  • 12
35
votes
3 answers

How to load all entries in an infinite scroll at once to parse the HTML in python

I am trying to extract information from this page. The page loads 10 items at a time, and I need to scroll to load all entries (for a total of 100). I am able to parse the HTML and get the information that I need for the first 10 entries, but I want…
user3093455
  • 393
  • 1
  • 5
  • 8
35
votes
9 answers

How to pass proxy-authentication (requires digest auth) by using python requests module

I was using Mechanize module a while ago, and now try to use Requests module. (Python mechanize doesn't work when HTTPS and Proxy Authentication required) I have to go through proxy-server when I access the Internet. The proxy-server requires…
yutaka2487
  • 1,926
  • 2
  • 13
  • 12
35
votes
12 answers

'Module object has no attribute 'get' Python error Requests?

I just installed the Requests module by using easy_install and I tried to run the demo code of this tutorial, import requests payload = {'username': 'xxxx', 'password': 'xxxxx'} r = requests.get('https://github.com/timeline.json') but I get this…
mojians
  • 641
  • 1
  • 6
  • 9
34
votes
7 answers

Can Python Requests library be used on Google App Engine?

Can I use Requests on Google App Engine? I think this library is perfect to create a REST client.
Dilvane Zanardine
  • 2,118
  • 3
  • 23
  • 23
34
votes
2 answers

URI encoding in Python Requests package

I am using python requests package to get results from a API and the URL contains + sign in it. but when I use requests.get, the request is failing as the API is not able to understand + sign. how ever if I replace + sign with %2B (URI Encoding) the…
user3435964
  • 663
  • 1
  • 11
  • 23
34
votes
3 answers

How do I get the IP address from a http request using the requests library?

I am making HTTP requests using the requests library in python, but I need the IP address from the server that responded to the HTTP request and I'm trying to avoid making two calls (and possibly having a different IP address from the one that…
gawry
  • 762
  • 1
  • 9
  • 18