本文介绍了Oauth 的导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 windows 上使用 Python 使用相同的代码,它工作正常,现在它突然改变了更新程序我发现错误 ImportError: 无法将名称导入到_native_string 你能帮我为什么会发生这个错误吗.

I am using Python on windows having working the same code it was working fine now it has suddent change for the updating the programme I found the error ImportError: cannot import name to_native_string can you help me why this error is occuring.

Traceback (most recent call last):
  File "C:\Users\inla\Desktop\tweepy2\tweepy1.py", line 1, in <module>
    from tweepy import Stream
  File "C:\Users\inla\Desktop\tweepy2\tweepy\__init__.py", line 16, in <module>
    from tweepy.auth import OAuthHandler, AppAuthHandler
  File "C:\Users\inla\Desktop\tweepy2\tweepy\auth.py", line 9, in <module>
    from requests_oauthlib import OAuth1Session, OAuth1
  File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.1-py2.7.egg\requests_oauthlib\__init__.py", line 1, in <module>
    from .oauth1_auth import OAuth1
  File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.1-py2.7.egg\requests_oauthlib\oauth1_auth.py", line 10, in <module>
    from requests.utils import to_native_string
ImportError: cannot import name to_native_string

推荐答案

检查您安装的 requests 版本.

Check your installed requests version.

requests.utils.to_native_stringrequests 2.0.0 起可用.

requests 升级到最新版本将解决您的问题.

Upgrading requests to latest version will solve your problem.

C:\Users\falsetru>pip install requests==1.2.3
Downloading/unpacking requests==1.2.3
...

Successfully installed requests
Cleaning up...

C:\Users\falsetru>python -c "from requests.utils import to_native_string"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name to_native_string

C:\Users\falsetru>pip uninstall -y requests
Uninstalling requests:
  Successfully uninstalled requests

C:\Users\falsetru>pip install requests==2.0.0
Downloading/unpacking requests==2.0.0
...

Successfully installed requests
Cleaning up...

C:\Users\falsetru>python -c "from requests.utils import to_native_string"

C:\Users\falsetru>

这篇关于Oauth 的导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:02