Error when using requests In Python2.7 - python

import requests
r = requests.get('http://bbs.byr.cn/')
print r
The error:
Traceback (most recent call last): File
"E:\MyPythonRoad\src\requeststest.py", line 1, in
import requests File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests__init__.py",
line 58, in
from . import utils File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\utils.py",
line 25, in
from .compat import parse_http_list as _parse_list_header File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\compat.py",
line 7, in
from .packages import chardet File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages__init__.py",
line 3, in
from . import urllib3 File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages\urllib3__init__.py",
line 16, in
from .connectionpool import ( File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages\urllib3\connectionpool.py",
line 36, in
from .connection import ( File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages\urllib3\connection.py",
line 43, in
from .util import ( ImportError: No module named util

requests
Since you are using Windows, you may want to try to reinstall requests through this binary.
urllib3
According to this, you may want to try manual download the util folder from urilib3 from the download at the bottom of pypi, and add it to the urllib3 install location.

Related

I can't use urllib3 or urllib in python 3.8 [duplicate]

This question already has answers here:
How can I import from the standard library, when my project has a module with the same name? (How can I control where Python looks for modules?)
(6 answers)
Closed 2 years ago.
I just installed urllib3 using pip command and was successful, and when i use import urllib3 or import urllib its showing a huge error. Why this happening?. Please help.
This is my error: when use import urllib or import urllib3 and running in sublime text.
Traceback (most recent call last):
File "C:\Users\Toshiba\Desktop\dd.py", line 1, in <module>
import urllib3
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 199, in load_module
mod = mod._resolve()
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 113, in _resolve
return _import_module(self.mod)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\utils.py", line 31, in <module>
import urllib.parse
File "C:\Users\Toshiba\Desktop\urllib.py", line 2, in <module>
from urllib3 import PoolManager
ImportError: cannot import name 'PoolManager' from partially initialized module 'urllib3' (most likely due to a circular import) (C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\__init__.py)
File "C:\Users\Toshiba\Desktop\urllib.py", line 2, in
One of your files is called urllib. Rename it.
That's one of the issues but I'm not sure it's the root cause of your problem. It seems like your installation is broken. If renaming this file didn't help, I'd suggest to start with a new virtualenv. If you're not using one, start with that.

cannot import name 'etree' from 'lxml' in home brew installed package but fine in python shell

I'm trying to run ocrmypdf which was installed via homebrew but am having issues with my local version of lxml (version 4.2.4):
Traceback (most recent call last):
File "/usr/local/bin/ocrmypdf", line 5, in <module>
from ocrmypdf.__main__ import run
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/ocrmypdf/__init__.py", line 18, in <module>
from . import helpers, hocrtransform, leptonica, pdfa, pdfinfo
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/ocrmypdf/pdfa.py", line 38, in <module>
import pikepdf
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/__init__.py", line 54, in <module>
from .models import (
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/models/__init__.py", line 13, in <module>
from .metadata import PdfMetadata
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/models/metadata.py", line 17, in <module>
from lxml import etree
ImportError: cannot import name 'etree' from 'lxml' ($HOME/anaconda3/lib/python3.7/site-packages/lxml/__init__.py)
If I open up a python shell, I'm able to import just fine:
>>> from lxml import etree
>>> etree.__file__
'$HOME/anaconda3/lib/python3.7/site-packages/lxml/etree.cpython-37m-darwin.so'
My pythonpath:
$HOME/anaconda3/lib/python3.7/site-packages:$HOME/Code_Repos/invoice2data//src:$HOME/Code_Repos/invoice2data//src/invoice2data:$HOME/anaconda3/lib/python3.7/site-packages:$HOME/Code_Repos/invoice2data
I'm not sure why the homebrewed package is not picking up the module file even though it says it's pointing to the same site-packages folder.

Cannot install drawnow

Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
File "c:\python27\lib\site-packages\pip\req\req_install.py", line 387, in setup_py
import setuptools # noqa
File "c:\python27\lib\site-packages\setuptools\__init__.py", line 12, in <module>
import setuptools.version
File "c:\python27\lib\site-packages\setuptools\version.py", line 1, in <module>
import pkg_resources
File "c:\python27\lib\site-packages\pkg_resources\__init__.py", line 49, in <module>
from six.moves import urllib, map, filter
ImportError: cannot import name urllib
how to solve this problem i already update pip

Import error in Flask (urllib in local path)

Am facing the below error while trying to import Flask. Similar questions posted had issues with Werkzeug versions
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request
File "init__.py", line 25, in <module>
from flask import Flask
File "user/anaconda/lib/python2.7/site-packages/flask/__init__.py", line 17,
in <module>
from werkzeug.exceptions import abort
File "user/anaconda/lib/python2.7/site-packages/werkzeug/__init__.py", line
154, in <module>
__import__('werkzeug.exceptions')
File "user/anaconda/lib/python2.7/site-packages/werkzeug/exceptions.py", line
71, in <module>
from werkzeug.wrappers import Response
File "user/anaconda/lib/python2.7/site-packages/werkzeug/wrappers.py", line
26, in <module>
from werkzeug.http import HTTP_STATUS_CODES, \
File "user/anaconda/lib/python2.7/site-packages/werkzeug/http.py", line 28, in
<module>
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request'
Werkzeug version(I tried with 10.1,10.4 ) still the error remains.
Someone pointed out that there might be a local copy of urllib2.. I
figured out that there was both urllib and urllib2 indeed in my
local path..
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
Now I am not sure how to proceed, Should I uninstall urllib/urllib2 ?
EDIT: The solution listed in Tried to use relative imports, and broke my import paths? doesn't work for me. In this case, I tried importing urllib2 into my Flask project and printing out the file path, but that throws the below exceptions
File "/user/__init__.py", line 25, in <module>
import urllib2
File "/user/anaconda/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/user/anaconda/lib/python2.7/httplib.py", line 80, in <module>
import mimetools
File "/user/anaconda/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/user/anaconda/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/user/anaconda/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/user/anaconda/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /user/anaconda/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup
I had a similar issue, and I followed the recommendation in the solution by adding from urllib2 import parse_http_list as _parse_list_header before from flask import Flask, then I got this error message:
"/Users/anaconda/lib/python2.7/io.py", line 51, in import _io
ImportError: dlopen(/Users/anaconda/lib/python2.7/lib-dynload/_io.so, 2):
Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Users/anaconda/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup
which I then resolved by following the solution:
sudo find / -name _io.so
I replaced /Users/anaconda/lib/python2.7/lib-dynload/_io.so with /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
It works for me!
In my case, one of my python-modules named uu. Such as a file in python3-email module.
... line 4, in <module>
import flask
File "/usr/lib/python3/dist-packages/werkzeug/http.py", line 28, in <module>
from urllib.request import parse_http_list as _parse_list_header
File "/usr/lib/python3.4/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.4/http/client.py", line 69, in <module>
import email.parser
File "/usr/lib/python3.4/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.4/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python3.4/email/message.py", line 10, in <module>
import uu
Then, i have the same error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/werkzeug/http.py", line 26, in <module>
from urllib2 import parse_http_list as _parse_list_header
ImportError: No module named 'urllib2'
I hope, this example will help you.

cannot import name WebApplicationClient

I am trying to run this program but I am receiving this error:
python questions_app.py
Traceback (most recent call last):
File "questions_app.py", line 8, in <module>
from filter_daemon import *
File "/home/mona/danac/queshuns/filter_daemon.py", line 5, in <module>
from twython import TwythonStreamer
File "/usr/local/lib/python2.7/dist-packages/twython/__init__.py", line 23, in <module>
from .api import Twython
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 14, in <module>
from requests_oauthlib import OAuth1, OAuth2
File "/usr/local/lib/python2.7/dist-packages/requests_oauthlib/__init__.py", line 3, in <module>
from .oauth2_auth import OAuth2
File "/usr/local/lib/python2.7/dist-packages/requests_oauthlib/oauth2_auth.py", line 2, in <module>
from oauthlib.oauth2 import WebApplicationClient, InsecureTransportError
ImportError: cannot import name WebApplicationClient
What are some possible options to solve it?
I am using Ubuntu 13.04 and Python 2.7.
It seems like you do not have oauthlib.
pip install oauthlib

Categories

Resources