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
71
votes
8 answers

Python-Requests close http connection

I was wondering, how do you close a connection with Requests (python-requests.org)? With httplib it's HTTPConnection.close(), but how do I do the same with Requests? Code: r = requests.post("https://stream.twitter.com/1/statuses/filter.json",…
user179169
69
votes
4 answers

Change the connection pool size for Python's "requests" module when in Threading

(edit: Perhaps I am wrong in what this error means. Is this indicating that the connection pool at my CLIENT is full? or a connection pool at the SERVER is full and this is the error my client is being given?) I am attempting to make a large…
68
votes
3 answers

Is the Session object from Python's Requests library thread safe?

Python's popular Requests library is said to be thread-safe on its home page, but no further details are given. If I call requests.session(), can I then safely pass this object to multiple threads like so: session = requests.session() for i in…
DJG
  • 6,413
  • 4
  • 30
  • 51
68
votes
3 answers

Get file size using python-requests, while only getting the header

I have looked at the requests documentation, but I can't seem to find anything. How do I only request the header, so I can assess filesize?
scandinavian_
  • 2,496
  • 1
  • 17
  • 19
68
votes
12 answers

How to save requests (python) cookies to a file?

How to use the library requests (in python) after a request #!/usr/bin/env python # -*- coding: utf-8 -*- import requests bot = requests.session() bot.get('http://google.com') to keep all the cookies in a file and then restore the cookies from a…
agrynchuk
  • 4,597
  • 3
  • 17
  • 17
67
votes
5 answers

Python requests exception handling

How to handle exceptions with python library requests? For example how to check is PC connected to internet? When I try try: requests.get('http://www.google.com') except ConnectionError: # handle the exception it gives me error name…
user1159798
67
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,781
  • 1
  • 20
  • 29
67
votes
10 answers

Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

I'm on Ubuntu 12.10 with OpenSSL 1.0.1c, python 2.7.3, Requests 1.0.3 and 1.0.4 (tried both), and when attempting to connect to the website in the url variable with the following code. def SendInitialRequest(xmlmessage, redirecturl): url =…
jasonamyers
  • 1,281
  • 1
  • 9
  • 11
67
votes
2 answers

How can I send an xml body using requests library?

def request(): #encoded_xml = urllib.urlencode({'XML': read_xml()}) #encoded_xml = read_xml() headers = {'Authorization': AUTH_TOKEN,\ 'developerToken': DEVELOPER_TOKEN,\ 'clientCostumerID': CLIENT_ID} …
Dimitris Leventeas
  • 1,622
  • 2
  • 16
  • 29
65
votes
8 answers

How to get pdf filename with Python requests?

I'm using the Python requests library to get a PDF file from the web. This works fine, but I now also want the original filename. If I go to a PDF file in Firefox and click download it already has a filename defined to save the pdf. How do I get…
kramer65
  • 50,427
  • 120
  • 308
  • 488
65
votes
3 answers

Python : Trying to POST form using requests

I'm trying to login a website for some scraping using Python and requests library, I am trying the following (which doesn't work): import requests headers = {'User-Agent': 'Mozilla/5.0'} payload = {'username':'niceusername','password':'123456'} In…
Captain_Meow_Meow
  • 2,341
  • 5
  • 31
  • 44
65
votes
6 answers

python ignore certificate validation urllib2

I want to ignore the certification validation during my request to the server with an internal corporate link. With python requests library I would do this: r = requests.get(link, allow_redirects=False,verify=False) How do I do the same with…
Sangamesh Hs
  • 1,447
  • 3
  • 24
  • 39
65
votes
2 answers

Passing csrftoken with python Requests

How do you pass a csrftoken with the python module Requests? This is what I have but it's not working, and I'm not sure which parameter to pass it into (data, headers, auth...) import requests from bs4 import BeautifulSoup URL =…
Jeff
  • 6,932
  • 7
  • 42
  • 72
65
votes
2 answers

How to specify python requests http put body?

I'm trying to rewrite some old python code with requests module. The purpose is to upload an attachment. The mail server requires the following specification…
omer bach
  • 2,345
  • 5
  • 30
  • 46
64
votes
5 answers

Fastest parallel requests in Python

I need to keep making many requests to about 150 APIs, on different servers. I work with the trading, time is crucial, I can not waste 1 millisecond. The solution and problems I found were these: Async using Asyncio: I do not want to rely on a…
Pedro Serra
  • 781
  • 1
  • 5
  • 8