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
42
votes
3 answers

multipart data POST using python requests: no multipart boundary was found

I have a form-data as well as file to be sent in the same POST. For ex, {duration: 2000, file: test.wav}. I saw the many threads here on multipart/form-data posting using python requests. They were useful, especially this one. My sample request is…
jeera
  • 591
  • 1
  • 7
  • 15
42
votes
4 answers

How to download and write a file from Github using Requests

Lets say there's a file that lives at the github repo: https://github.com/someguy/brilliant/blob/master/somefile.txt I'm trying to use requests to request this file, write the content of it to disk in the current working directory where it can be…
Fomite
  • 2,213
  • 7
  • 30
  • 46
41
votes
4 answers

Request returns bytes and I'm failing to decode them

Essentially I made a request to a website and got a byte response back: b'[{"geonameId:"703448"}..........'. I'm confused because although it is of type byte, it is very human readable and appears like a list of json. I do know that the response…
koda gates
  • 413
  • 1
  • 4
  • 5
41
votes
9 answers

python requests ssl handshake failure

Every time I try to do: requests.get('https://url') I got this message: import requests >>> requests.get('https://reviews.gethuman.com/companies') Traceback (most recent call last): File "", line 1, in File…
Idan Haim Shalom
  • 1,234
  • 1
  • 11
  • 19
41
votes
5 answers

how to use github api token in python for requesting

I'm able to obtain Github api token in python using username and password but i'm not able to use that API-Token for requesting any POST/DELETE/PATCH. How do we use Github API-Tokens for making any request. For eg, i have API-Token lets say…
softvar
  • 17,917
  • 12
  • 55
  • 76
40
votes
4 answers

How to get the raw content of a response in requests with Python?

Trying to get the raw data of the HTTP response content in requests in Python. I am interested in forwarding the response through another channel, which means that ideally the content should be as pristine as possible. What would be a good way to do…
Juan Carlos Coto
  • 11,900
  • 22
  • 62
  • 102
39
votes
4 answers

How do I load session and cookies from Selenium browser to requests library in Python?

How can I load session and cookies from Selenium browser? The following code: import requests cookies = [{u'domain': u'academics.vit.ac.in', u'name': u'ASPSESSIONIDAEQDTQRB', u'value': u'ADGIJGJDDGLFIIOCEZJHJCGC', …
Cibin
  • 590
  • 1
  • 7
  • 13
39
votes
1 answer

Build a URL using Requests module Python

Is it possible to build a URL using the Requests library for Python? Building a query string is supported but what about building the rest of the URL. Specifically I'd be interested in adding on to the base URL with URL encoded strings: http ://…
Jimbo
  • 2,886
  • 2
  • 29
  • 45
38
votes
6 answers

Is there a way to globally override requests' timeout setting?

We have usages of the requests library littered throughout our project. Recently we came across a bug in one of our destinations where it froze mid transaction, and decided to just hold the connection open. Naturally, our application followed…
Shadow
  • 8,749
  • 4
  • 47
  • 57
38
votes
1 answer

Python requests with multithreading

I've been trying to build a scraper with multithreading functionality past two days. Somehow I still couldn't manage it. At first I tried regular multithreading approach with threading module but it wasn't faster than using a single thread. Later I…
krypt
  • 439
  • 1
  • 4
  • 13
38
votes
2 answers

How to make python .post() requests to retry?

I'm trying to implement requests retry in Python. It works like charm with .get() requests, but a .post() request never retries, regardless of a status code. I'd like to use it with .post() requests. My code: from requests.packages.urllib3.util…
user1554733
38
votes
2 answers

python requests link headers

I'm trying to find best way to capture links listed under response headers, exactly like this one and I'm using python requests module. Below is link which has Link Headers section on Python Requests…
Malhar
  • 503
  • 1
  • 4
  • 6
38
votes
4 answers

Http Redirection code 3XX in python requests

I am trying to capture http status code 3XX/302 for a redirection url. But I cannot get it because it gives 200 status code. Here is the code: import requests r = requests.get('http://goo.gl/NZek5') print r.status_code I suppose this should issue…
Bishwash
  • 854
  • 1
  • 9
  • 22
38
votes
9 answers

Login to Facebook using python requests

I'm trying to find a way to automatically login to Facebook without browser using Python. I experimented with "requests" lib. Tried several ways: URL = 'http://m.facebook.com' requests.get(URL, auth = ('email@domain.com',…
alexryabkov
  • 493
  • 1
  • 5
  • 8
37
votes
11 answers

Telegram Bot "chat not found"

I have the following code in Python to send a message to myself from a bot. import requests token = '123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI' method = 'sendMessage' myuserid = 1949275XX response = requests.post( …
Bijan
  • 7,737
  • 18
  • 89
  • 149