seanmonstar / reqwest

An easy and powerful Rust HTTP Client
https://docs.rs/reqwest
Apache License 2.0
9.67k stars 1.09k forks source link

Cannot make requests to localhost #913

Open creativcoder opened 4 years ago

creativcoder commented 4 years ago

In Python's (3.5.2) requests:

>>> r = requests.get('http://localhost:4000')
>>> r
<Response [200]>

Whereas in reqwest:

reqwest::get("http://localhost:4000")

Fails with an error:

Error: reqwest::Error { kind: Decode, source: Error("expected value", line: 1, column: 1) }

Use case: I am using reqwests as an HTTP client in a web scraper to scrape a page hosted on localhost. The page is hosted on localhost to provide a reproducible/imuutable test environment for the scraper.

If this is a bug, I would like to make a fix.

seanmonstar commented 4 years ago

Can you post the response headers? It kind of looks like gzip decoding is failing...

creativcoder commented 4 years ago
>>> r.headers
{'Date': 'Sat, 16 May 2020 18:33:13 GMT', 'Content-Length': '11', 'Content-Type': 'text/plain; charset=UTF-8', 'Server': 'tiny-http (Rust)'}
tafia commented 3 years ago

I got some similar error. It was because it was using proxy even for localhost connections. Setting the no_proxy worked.