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
4
votes
1 answer

Python 3 - requests library - iter_lines - Handling possible server stalls when reading chunk of streamed data

I need to find out a way to smoothly manage server stalls when I have been reading data from it. I wrote the piece of code below: def listener(): resp = requests.get(someurl, stream=True) if resp.status_code == 200: for line in…
AntoG
  • 833
  • 1
  • 10
  • 16
4
votes
2 answers

How to web scrape in an .jsf site with cookies and javascript "javax.faces.ViewState" CDATA using python requests and bs4 (BeautifulSoup) modules?

I would like to automate the extraction of data from this site: http://www.snirh.gov.br/hidroweb/publico/medicoes_historicas_abas.jsf Explanation of the steps to be followed for extract the data that I want: Beginning in the url above click in…
pedro regis
  • 316
  • 4
  • 6
4
votes
2 answers

Returning 403 Forbidden from simple get but loads okay in browser

I'm trying to get some data from a page, but it's returning the error [403 Forbidden]. I thought it was the user agent, but I tried several user agents and it still returns the error. I also tried to use the library fake user-agent but I did not…
Mathiasfc
  • 1,627
  • 1
  • 16
  • 24
4
votes
2 answers

How to remove Http 401 Unauthorized error using python3

I am trying to access web resource secured with HTTPBasicAuth using python3. I am providing the right credentials still it is showing 401 unauthorized error. I am using urllib for doing it as I failed to do it using requests module because of ssl…
4
votes
2 answers

python : request dependency idna failed "ImportError: No module named idna"

I am using the request module in python, which has inda as a dependency. I am keeping idna module inside request module but still it is not able to detect the inda module.…
4
votes
0 answers

Correct way to handle custom API error messages in Requests?

I'm using the Python Requests library to call an API that may return custom error messages in it's JSON response, i.e. something like this: { "error": "TOKEN INVALID" } I would like to have a custom exception class with this error message as…
gmolau
  • 2,815
  • 1
  • 22
  • 45
4
votes
0 answers

Python requests zip upload makes zipfile unreadable in Windows

I'm trying to upload a zipfile to a Server using Python requests. The upload works fine. However the uploaded file cannot be opened using Windows Explorer or ark. I suppose there's some problem with mime-type or content-Length. Oddly, uploading the…
TheFrozenOne
  • 141
  • 3
4
votes
3 answers

Scrape Google Quick Answer Box in Python

I am very new to Python programming and I am trying to make a simple application. What I'm trying to do is search for a text on Google and return the links, my program does this fine. The other thing is if Google has the quick answer like in the…
4
votes
1 answer

Getting [Errno 110] 'Connection timed out' when trying to do get requests in python

I am able to access the below "URL" mentioned in code manually in firefox browser and see the json response as : { "version" : "1.0", "email_address" : "xxxx@emailin.com" } But when I am trying to do get request with below code I am getting…
Sum
  • 363
  • 2
  • 4
  • 16
4
votes
0 answers

json.load() VS request.json()

I am quite new to python and Flask and in a recent code review I had quite interesting conversation about using the json package to parse a json response. My code was simply doing this: return json.loads(response.text) The suggested change was…
vertigo
  • 41
  • 1
4
votes
1 answer

Error with Python and XML

I'm getting an error when trying to grab a value from my XML. I get "Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration." Here is my code: import requests import lxml.etree from…
Dan
  • 359
  • 5
  • 17
4
votes
2 answers

Adding Multiple .xls files to a Single .xls file, using the file name to name tabs

I have multiple directories, each of which containing any number of .xls files. I'd like to take the files in any given directory and combine them into one .xls file, using the file names as the tab names. For example if there are the files…
MEd
  • 41
  • 1
4
votes
3 answers

requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read, 512 more expected)', IncompleteRead

I wanted to write a program to fetch tweets from Twitter and then do sentiment analysis. I wrote the following code and got the error even after importing all the necessary libraries. I'm relatively new to data science, so please help me. I could…
4
votes
1 answer

Do Python 3.6 and Requests Module conform to RFC 6125 for wildcard reference identifiers?

I am trying to ascertain whether Python's request module conforms to RFC 6125 or not. I created a Root CA Certificate and added it to my Linux's Trust Store. I then created a Server certificate and signed it with my Root CA Certificate and put the…
Hussain Ali Akbar
  • 1,585
  • 2
  • 16
  • 28
4
votes
1 answer

In Python 3, requests.get() gives incomplete json response

I am trying to get data using requests.get(). And the response data is large(containing 10000 mongodb records). But the response I get is almost always broken. Very few times I got the correct result. Example: Should be like this: [ { …
Deepak
  • 3,134
  • 2
  • 24
  • 24