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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 95, in <module>
    from urllib3.contrib import pyopenssl
  File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
    import OpenSSL.SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in <module>
    from cryptography import x509
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 8, in <module>
    from cryptography.x509.base import (
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/base.py", line 16, in <module>
    from cryptography.x509.extensions import Extension, ExtensionType
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/extensions.py", line 24, in <module>
    from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/general_name.py", line 18, in <module>
    from cryptography.x509.name import Name
  File "/usr/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <module>
    _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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值