Python引入 requests 会报UnicodeDecodeError

谭十二 2017-04-12 03:31:34
UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not in range(128)

D:\codeSoft\Python2\python.exe "D:\program files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 5504 --file E:/anCode/pycharm/rexx/lesson3/xpathTest3_thread.py
pydev debugger: process 13136 is connecting

Connected to pydev debugger (build 163.10154.50)
Traceback (most recent call last):
File "D:\program files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "D:\program files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "E:/anCode/pycharm/rexx/lesson3/xpathTest3_thread.py", line 4, in <module>
import requests
File "D:\codeSoft\Python2\lib\site-packages\requests\__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "D:\codeSoft\Python2\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 47, in <module>
from cryptography import x509
File "D:\codeSoft\Python2\lib\site-packages\cryptography\x509\__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "D:\codeSoft\Python2\lib\site-packages\cryptography\x509\base.py", line 16, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "D:\codeSoft\Python2\lib\site-packages\cryptography\x509\extensions.py", line 14, in <module>
from asn1crypto.keys import PublicKeyInfo
File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\keys.py", line 22, in <module>
from ._elliptic_curve import (
File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\_elliptic_curve.py", line 51, in <module>
from ._int import inverse_mod
File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\_int.py", line 56, in <module>
from ._perf._big_num_ctypes import libcrypto
File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\_perf\_big_num_ctypes.py", line 31, in <module>
libcrypto_path = find_library('crypto')
File "D:\codeSoft\Python2\lib\ctypes\util.py", line 53, in find_library
fname = os.path.join(directory, name)
File "D:\codeSoft\Python2\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not in range(128)

Process finished with exit code 1
...全文
762 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_32396103 2017-09-21
  • 打赏
  • 举报
回复
楼主这个问题解决了吗我跟你遇到一样的问题
zangree 2017-06-20
  • 打赏
  • 举报
回复
我的问题解决了,因为环境变量中有中文字符。
zangree 2017-06-19
  • 打赏
  • 举报
回复
我也遇见这个问题,import cryptography.x508,会报同样的错误
风华渐逝 2017-04-19
  • 打赏
  • 举报
回复
可以装个PyCharm,里面有个package管理功能,看看 requests 是否有被正确安装
sanGuo_uu 2017-04-18
  • 打赏
  • 举报
回复
抱歉,这问题我解决不了
谭十二 2017-04-18
  • 打赏
  • 举报
回复
@sanGuo_u C:\Users\伟超>pip install requests Requirement already satisfied: requests in d:\codesoft\python2\lib\site-packages C:\Users\伟超>python Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit ( Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\codeSoft\Python2\lib\site-packages\requests\__init__.py", line 52, in <module> from .packages.urllib3.contrib import pyopenssl File "D:\codeSoft\Python2\lib\site-packages\requests\packages\urllib3\contrib\ pyopenssl.py", line 47, in <module> from cryptography import x509 File "D:\codeSoft\Python2\lib\site-packages\cryptography\x509\__init__.py", li ne 7, in <module> from cryptography.x509.base import ( File "D:\codeSoft\Python2\lib\site-packages\cryptography\x509\base.py", line 1 6, in <module> from cryptography.x509.extensions import Extension, ExtensionType File "D:\codeSoft\Python2\lib\site-packages\cryptography\x509\extensions.py", line 14, in <module> from asn1crypto.keys import PublicKeyInfo File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\keys.py", line 22, in < module> from ._elliptic_curve import ( File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\_elliptic_curve.py", li ne 51, in <module> from ._int import inverse_mod File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\_int.py", line 56, in < module> from ._perf._big_num_ctypes import libcrypto File "D:\codeSoft\Python2\lib\site-packages\asn1crypto\_perf\_big_num_ctypes.p y", line 31, in <module> libcrypto_path = find_library('crypto') File "D:\codeSoft\Python2\lib\ctypes\util.py", line 53, in find_library fname = os.path.join(directory, name) File "D:\codeSoft\Python2\lib\ntpath.py", line 85, in join result_path = result_path + p_path UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not in range(128)
谭十二 2017-04-16
  • 打赏
  • 举报
回复
@sanGuo_u 大神你好,源码见楼上,报错时提示 import requests 这一行 出错,以前没有这种情况,后来有的
sanGuo_uu 2017-04-16
  • 打赏
  • 举报
回复
引用 4 楼 Thoremp 的回复:
@sanGuo_u 大神你好,源码见楼上,报错时提示 import requests 这一行 出错,以前没有这种情况,后来有的
我用给你给的代码试了试,没有报错 这个是运行结果
['9.6', '9.4', '9.5', '9.4', '9.5', '9.2', '9.4', '9.2', '9.2', '9.3', '9.2', '9.1', '9.2', '9.2', '9.1', '9.2', '9.1', '9.0', '9.2', '9.1', '8.9', '9.1', '9.0', '9.3', '9.0']
9.6
9.4
9.5
9.4
9.5
9.2
9.4
9.2
9.2
9.3
9.2
9.1
9.2
9.2
9.1
9.2
9.1
9.0
9.2
9.1
8.9
9.1
9.0
9.3
9.0
你说 import requests ,这个报错。是不是说没有这个模块? 如果没有,就pip install requests
谭十二 2017-04-14
  • 打赏
  • 举报
回复
下面是源码QAQ
# -*- coding:utf-8 -*-

from lxml import etree
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import requests

url = "https://movie.douban.com/top250"

html = requests.get(url).text
selector = etree.HTML(html)

movies = selector.xpath('//div[@class="info"]/div[@class="bd"]/div[@class="star"]/span[@class="rating_num"]/text()')

print movies
for each in movies:
    print each
wutong9509 2017-04-12
  • 打赏
  • 举报
回复
无源码,无真相
sanGuo_uu 2017-04-12
  • 打赏
  • 举报
回复
你要放代码啊,不然不好说清 --------------------------------------------------- 提示已经很明显了,它说ascii转换出问题。 肯定是你把某些内容,放进一个文件(或变量)里,然后那个文件是ascii编码的,所以就报错了。 --------------------------------------------------

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧