question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected exception: InvalidURL: No host specified.

See original GitHub issue

I have some legacy code that calls requests like this:

response = requests.get(file_resource['url'], stream=True)

Through debug statements right before that statement I see that the passed url is like:

http://xxxxxx.xxxx.xxx.int/xxx-sl-int/data-action?ProductType=MAP&MAP.MAP_OID=12655

That url, btw, correctly resolves into a 200MB file, in the browser or through a curl/wget download.

Expected Result

I’d expect my file to be downloaded (when I later try to:

for block in response.iter_content(100 * 1024):
                            handle.write(block)

Actual Result

I get the following stack trace:

Failed with: Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 710, in perform_job
    rv = job.perform()

  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 560, in perform
    self._result = self._execute()

  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 566, in _execute
    return self.func(*self.args, **self.kwargs)

  File "/plaavi/components/file_cache/worker.py", line 1131, in download
    return worker.download(fileResource)

  File "/plaavi/components/file_cache/worker.py", line 112, in download
    response = requests.get(file_resource['url'], stream=True)

  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)

  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 668, in send
    history = [resp for resp in gen] if allow_redirects else []

  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 247, in resolve_redirects
    **adapter_kwargs

  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 414, in send
    raise InvalidURL(e, request=request)

InvalidURL: No host specified.

Reproduction Steps

>>> import requests
>>> response = requests.get("http://xxxxxx.xxxx.xxx.int/xxx-sl-int/data-action?ProductType=MAP&MAP.MAP_OID=12655", stream=True)
>>> response
<Response [200]>

Apparently trying the request from the same-ish machine that cause the exception, is working.

What is different in the actual exception case, is that the request to download happens inside an RQ (http://python-rq.org/) worker running inside a docker container, that I do not know how to further debug. Mind you that kind of download infrastructure, was working correctly the last two years and only now it starts to have these downloading issues.

System Information

The docker container is setup like this:

$ python -m requests.help
root@9dd4bc57a320:/tmp# python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.2.1"
  },
  "idna": {
    "version": ""
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.6"
  },
  "platform": {
    "release": "3.10.0-862.11.6.el7.x86_64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1010007f",
    "version": "18.0.0"
  },
  "requests": {
    "version": "2.20.1"
  },
  "system_ssl": {
    "version": "1000106f"
  },
  "urllib3": {
    "version": "1.24.1"
  },
  "using_pyopenssl": true
}

This command is only available on Requests v2.16.4 and greater. Otherwise, please provide some basic information about your system (Python version, operating system, &c).

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sigmavirus24commented, Nov 12, 2018

follows a non existent redirect, (as my url does not redirect anywhere),

We do exactly what the server tells us meaning that your URL must redirect somewhere.

This is not a bug in Requests and this is not a forum for helping you debug your infrastructure. It’s only for actual defects in Requests, which this does not appear to be.

0reactions
stratosgearcommented, Nov 12, 2018

For completeness sake this was an issue in our code base. There was a rogue:

httplib.HTTPConnection._http_vsn = 10
httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0'

that I have no idea what it was trying to achieve, Removing this, helps the url to resolve correctly.

And yes, I know this is not a forum, but I did not ask anyone to help me debug my infrastructure. I honestly thought that I came across a requests bug, and I did whatever was humanly possible to debug the issue as best I could, even patching requests to help me find where the issue was. I provided, step by step progress report on what I was doing along the way. Ok, it’s finally an issue in our infrastructure but that last comment was uncalled for, and really leaves me walking away from here with a bad taste in my mouth…

Read more comments on GitHub >

github_iconTop Results From Across the Web

No host supplied : error while using Request.get(url) in Python
Correct way to try/except using Python requests module? 2 · requests.exceptions.MissingSchema: Invalid URL 'h': No schema supplied · 1.
Read more >
Python Examples of requests.exceptions.InvalidURL
This page shows Python examples of requests.exceptions.InvalidURL.
Read more >
Web scraping errors - Python Forum
Hi! Can someone please help a newbie here. Im trying to download all the images from xkcd.com, using the code from the book...
Read more >
MissingSchema: Invalid URL ' ': No schema supplied
Solved: Using Python 3.6.9, I'm making requests with Requests by calling URLs from a text file. I put five of them here, for...
Read more >
Error and Warning Dictionary | Twilio
Explore the full list of all possible Twilio REST API error codes. ... Programmable Chat: Parameters are not specified for update request.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found