Closed phdegnan closed 8 years ago
I haven't had a chance to look into this yet but I just want to sincerely thank you for such a wonderfully detailed bug report. :cake:
So I refreshed my memory of the code that might be triggering this exception.
Your version of requests is supported (we test against 2.2.1 explicitly), but I'm a bit surprised we haven't run into this before. urllib3 1.7.1 is the actual culprit here as it did not include the urllib3.connection
module until a later release.
So we'll need to figure out how to get what we need from those versions of urllib3. As best I can tell, the only thing we need from the urllib3.connection
module is the HTTPConnection
class and that's only for a feature we only support for versions of requests >= 2.4.0.
It shouldn't be terribly difficult to only conditional perform that import in requests_toolbelt._compat
. Since the module is private we have no backwards compatibility guarantees to users.
Would you like to try doing that @phdegnan?
If you can tell me what precisely to do I'm happy to try. When it comes to coding I'm not even semi-pro.
It also seems that I could update requests
to achieve a similar result?
So you'll need to edit 2 files:
requests_toolbelt/_compat.py
requests_toolbelt/adapters/socket_options.py
In the first you'll want the code to look something like:
# requests_toolbelt/_compat.py
import requests
if requests.__build__ >= 0x020400:
try:
from requests.packages.urllib3 import connection
except ImportError:
from urllib3 import connection
else:
connection = None
And you want to remove the lines from this try
/except
block that match the ones above.
Then you'll want to edit this block to look like
# requests_toolbelt/adapters/socket_options.py
class SocketOptionsAdapter(adapters.HTTPAdapter):
""" ....
"""
if connection is not None:
# What is presently there
else:
default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]
Great - I'll give it a whirl and get back to you. Cheers!
Awesome! Thanks for reporting & fixing this!
Side note: The reason our testing didn't catch this on 2.2.1 is because requests had a version that was newer than 1.7.1 bundled which did include the urllib3.connection module
. Even 2.1.0 has the connection.py
file (and so does 2.1.0).
So the fault for this is squarely on the distro packaging. This is very disappointing. Still I'd rather handle this for users like @phdegnan than ignore it as a problem out of our control. (I just wish the distributions weren't this awful with the packages they provide users.)
Well, their code compiles without error.
$ ./tools/bin/mg-download.py -h
NAME
mg-download
VERSION
1
SYNOPSIS
mg-download [ --help, --user <user>, --passwd <password>, --token <oAuth token>, --project <project id>, --metagenome <metagenome id>, --file <file id> --dir <directory name> --list <list files for given id>]
...
Actually retrieving data from the MG-RAST server seems ungodly slow. Hopefully that is their fault...
Thanks for the timely assistance!
@phdegnan are you going to send a PR?
I can.
I have the same issue in package, provided in Ubuntu Server 14.04. Fix, described by you doesn't helps. The error now is:
ImportError: No module named packages.urllib3.poolmanager
Would it be fixed?
@pensnarik how did you install requests and the requests toolbelt?
This is related to https://github.com/sigmavirus24/requests-toolbelt/issues/82 - which appeared to have been fixed by 0.5.1 - but perhaps some of my installed versions are old. Installation and system details are below.
I'm trying to get the MG-RAST API running (https://github.com/MG-RAST/MG-RAST-Tools). I had to install requests-toolbelt which seemed to go fine:
Path variable updates were added for local directories and MG-RAST-Tools:
But when I run the main script I get the following error message:
Per #82 my system installation is thus:
I haven't tried updating requests based on pbkhrv's in #82 that it broke pip. Any suggestions would be great. Best, Patrick