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
24
votes
2 answers

Python Requests encoding POST data

Version: Python 2.7.3 Other libraries: Python-Requests 1.2.3, jinja2 (2.6) I have a script that submits data to a forum and the problem is that non-ascii characters appear as garbage. For instance a name like André Téchiné comes out as André…
TheMagician
  • 1,846
  • 7
  • 20
  • 26
24
votes
1 answer

Python requests - POST data from a file

I have used curl to send POST requests with data from files. I am trying to achieve the same using python requests module. Here is my python script import requests payload=open('data','rb').read() r = requests.post('https://IP_ADDRESS/rest/rest/2',…
skanagasabap
  • 910
  • 3
  • 12
  • 24
23
votes
3 answers

Getting HEAD content with Python Requests

I'm trying to parse the result of a HEAD request done using the Python Requests library, but can't seem to access the response content. According to the docs, I should be able to access the content from requests.Response.text. This works fine for me…
Yarin
  • 173,523
  • 149
  • 402
  • 512
23
votes
8 answers

Python at AWS Lambda: `requests` from botocore.vendored deprecated, but `requests` not available

I've got a Python script for an AWS Lambda function that does HTTP POST requests to another endpoint. Since Python's urllib2.request, https://docs.python.org/2/library/urllib2.html, can only handle data in the standard…
23
votes
5 answers

"RecursionError: maximum recursion depth exceeded" from ssl.py: `super(SSLContext, SSLContext).options.__set__(self, value)`

I am using Python 3.6.5 on the following remote server setup: Server: Windows 10 Python: 3.6.5 Requests: 2.18.4 Pentaho: 8.0 When I run request.get against URLs in the server's command prompt, it gets the JSON as expected: >>> import…
user3871
  • 12,432
  • 33
  • 128
  • 268
23
votes
4 answers

Send http request through specific network interface

I have two network interfaces (wifi and ethernet) both with internet access. Let's say my interfaces are eth (ethernet) and wlp2 (wifi). I need specific requests to go through eth interface and others through wpl2. Something like: // Through…
epinal
  • 1,415
  • 1
  • 13
  • 27
23
votes
3 answers

Check if a large file exists without downloading it

Not sure if this is possible, but I would like to check the status code of an HTTP request to a large file without downloading it; I just want to check if it's present on the server. Is it possible to do this with Python's requests? I already know…
Juicy
  • 11,840
  • 35
  • 123
  • 212
23
votes
3 answers

Python Requests - retry request after re-authentication

I am using Python 3.5.1 with Requests 2.9.1. My use case as follows: I need to authenticate (get a token) from service T and use it as value of the Authorization header when making requests to a resource server R. The token expires at some point and…
wujek
  • 10,112
  • 12
  • 52
  • 88
23
votes
3 answers

Saving a json file to computer python

Using requests in Python I am performing a GET, requesting a JSON file which I can later access and modify, tweak, etc. with the command solditems.json(). However I would like to save this JSON file to my computer. Looking through the requests docs…
ark
  • 749
  • 3
  • 8
  • 29
22
votes
5 answers

python-requests: order get parameters

I am implementing a client library for a private HTTP-API using python requests. The API(which I don't control) expects the parameters to be in a certain order, but python-requests doesn't honor a sorted dict as parameter. This is what i…
tback
  • 11,138
  • 7
  • 47
  • 71
22
votes
2 answers

Multiple async requests simultaneously

I'm trying to call ~ 300 API calls at the same time, so that I would get the results in a couple of seconds max. My pseudo-code looks like this: def function_1(): colors = ['yellow', 'green', 'blue', + ~300 other ones] loop =…
Costantin
  • 2,486
  • 6
  • 31
  • 48
22
votes
2 answers

Implementing retry for requests in Python

How do I implement a retry count of 5 times, 10 seconds apart when sending a POST request using the requests package. I have found plenty of examples for GET requests, just not post. This is what I am working with at the moment, sometimes I get a…
Phil Baines
  • 437
  • 1
  • 6
  • 18
22
votes
1 answer

How do I sign a POST request using HMAC-SHA512 and the Python requests library?

I'm trying to use Python to access the trading API at poloniex.com, a cryptocurrency exchange. To do this I must follow this prescription: All calls to the trading API are sent via HTTP POST to https://poloniex.com/tradingApi and must contain the…
Werhli
  • 251
  • 1
  • 2
  • 4
22
votes
5 answers

What's the correct way to use a unix domain socket in requests framework?

Usually, doing a post request using requests framework is done by: payload = {'key1': 'value1', 'key2': 'value2'} r = requests.post("http://httpbin.org/post", data=payload) But: How do I connect to a unix socket instead of doing a TCP…
Luis Masuelli
  • 12,079
  • 10
  • 49
  • 87
22
votes
1 answer

Clear cookies from Requests Python

I created variable: s = requests.session() how to clear all cookies in this variable?
user3537765
  • 301
  • 1
  • 4
  • 10