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
64
votes
6 answers

Python SSL certificate verify error

I'm using requests to access a RESTful API. Everything seems to work. I can authenticate, pull back a session token and even unit test the methods in my class I wrote for the API. Then I tried to run my code. First, here is the call I'm making. …
Tim B
  • 876
  • 1
  • 7
  • 12
64
votes
2 answers

Changing the referer URL in python requests

How do I change the referer if I'm using the requests library to make a GET request to a web page. I went through the entire manual but couldn't find it.
Mayank Kumar
  • 1,133
  • 3
  • 13
  • 20
63
votes
8 answers

Progress Bar while download file over http with Requests

I need to download a sizable (~200MB) file. I figured out how to download and save the file with here. It would be nice to have a progress bar to know how much has been downloaded. I found ProgressBar but I'm not sure how to incorperate the two…
Gamegoofs2
  • 813
  • 1
  • 8
  • 15
60
votes
4 answers

Python Requests vs PyCurl Performance

How does the Requests library compare with the PyCurl performance wise? My understanding is that Requests is a python wrapper for urllib whereas PyCurl is a python wrapper for libcurl which is native, so PyCurl should get better performance, but…
Eugene
  • 10,957
  • 20
  • 69
  • 97
59
votes
3 answers

Python requests module sends JSON string instead of x-www-form-urlencoded param string

I was under the impression that POSTSs using x-www-form-urlencoded specifications should send a URL encoded param string in the body of the post. However, when I do this data = json.dumps({'param1': 'value1', 'param2': 'value2'}) Requests.post(url,…
asolberg
  • 6,638
  • 9
  • 33
  • 46
57
votes
4 answers

When to use `raise_for_status` vs `status_code` testing

I have always used: r = requests.get(url) if r.status_code == 200: # my passing code else: # anything else, if this even exists Now I was working on another issue and decided to allow for other errors and am instead now using: try: r =…
Madivad
  • 2,999
  • 7
  • 33
  • 60
57
votes
4 answers

Requests — how to tell if you're getting a success message?

My question is closely related to this one. I'm using the Requests library to hit an HTTP endpoint. I want to check if the response is a success. I am currently doing this: r = requests.get(url) if 200 <= response.status_code <= 299: # Do…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
57
votes
1 answer

How do I set the content-type for POST requests in python-requests library?

One API I'm currently using specifies that I need a special content-type string. I don't know how do I set this in python-requests library
EnderSodium
  • 701
  • 1
  • 5
  • 4
57
votes
3 answers

Measure website load time with Python requests

I'm trying to build a tool for testing the delay of my internet connection, more specifically web site load times. I thought of using the python requests module for the loading part. Problem is, it's got no built-in functionality to measure the time…
cookM
  • 953
  • 3
  • 8
  • 11
55
votes
5 answers

Create a functioning Response object

For testing purposes I'm trying to create a Response() object in python but it proves harder then it sounds. i tried this: from requests.models import Response the_response = Response() the_response.code = "expired" the_response.error_type =…
Dotan
  • 6,602
  • 10
  • 34
  • 47
54
votes
2 answers

SystemError: error return without exception set, when using requests and debugger

Environment: Python 3.6.3 Requests 2.18.4 PyCharm 2018.1 When using the above configuration in normal run everything is fine. However,when using PyCharm debugger my output is constantly giving me two kinds of exceptions: Exception ignored in:…
CodeSamurai777
  • 3,285
  • 2
  • 24
  • 42
54
votes
5 answers

Querystring Array Parameters in Python using Requests

I have been trying to figure out how to use python-requests to send a request that the url looks like: http://example.com/api/add.json?name='hello'&data[]='hello'&data[]='world' Normally I can build a dictionary and do: data = {'name': 'hello',…
Buddy Lindsey
  • 3,560
  • 6
  • 30
  • 42
53
votes
1 answer

how to get redirect url using python requests

r = requests.get('http://techtv.mit.edu/videos/1585-music-session-02/download.source') for i in r.history: print(i.url) I think it should print out the history, but it doesn't, the above url points to a video, but I cannot get it, anyone…
1a1a11a
  • 1,187
  • 2
  • 16
  • 25
53
votes
1 answer

Difference between "data" and "params" in Python requests?

I was curious what the difference was between the data parameter and the params parameter in a python-requests request, and when each should be used. One example is I have an array of dicts users=[{"email_hash": "fh7834uifre8houi3f"}, ... ] and I…
tscizzle
  • 11,191
  • 15
  • 54
  • 88
53
votes
5 answers

Return a requests.Response object from Flask

I'm trying to build a simple proxy using Flask and requests. The code is as follows: @app.route('/es///', methods=['GET', 'POST', 'PUT']): def es(index, type, id): elasticsearch =…
Fred Foo
  • 355,277
  • 75
  • 744
  • 836