requests import就报错

TypeError when importing  from python

Ask Question

up vote0down votefavorite

I'm having problems using the requests library. I used pip to install it and I also intalled through github and the installation goes just fine. But when I try to import the lib, I get this error:

Python 2.7.14+ (default, Mar 13 2018, 15:23:44) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 95, in 
    from urllib3.contrib import pyopenssl
  File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in 
    import OpenSSL.SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in 
    from OpenSSL import crypto, SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in 
    from cryptography import x509
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 8, in 
    from cryptography.x509.base import (
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/base.py", line 16, in 
    from cryptography.x509.extensions import Extension, ExtensionType
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/extensions.py", line 24, in 
    from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/general_name.py", line 18, in 
    from cryptography.x509.name import Name
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in 
    _ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
TypeError: 'type' object is not iterable
>>> 

I saw in another post a person saying something about the PATH, but I didn't understand... Something related to a conflict between /usr/bin and /usr/local/bin. I don't know if this have something to do with it. I also have used pip2.7 to install the lib and it shows in the pip listcommand. I'd appreciate any help.

python python-requests typeerror

shareimprove this question

asked Mar 27 at 9:56

Ulisses Alves

51

  • 1

    Have you seen this: github.com/pyca/cryptography/issues/4020 and tried the sudo pip uninstall enumfollowed by sudo pip install enum34? – FlyingTeller Mar 27 at 10:16

  • Oh man, I saw this before, but for some reason I forgot to uninstall the enum. Problem solved. Thanks! – Ulisses Alves Mar 27 at 10:22

  • I'll post it as an answer for future readers that find this page – FlyingTeller Mar 27 at 10:27

add a comment

1 Answer

activeoldestvotes

up vote0down voteaccepted

The issue is in the cryptography module. It can also be found on the github page. The solution seems to be that you need to replace the enum package:

pip uninstall enum
pip install enum34

Note that you need to use sudo pip if you are using packages from /usr/

你可能感兴趣的:(技术贴)