Import error for Oauth

不问归期 提交于 2019-12-19 17:34:20

问题


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

回答1:


Check your installed requests version.

requests.utils.to_native_string is available since requests 2.0.0.

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>


来源:https://stackoverflow.com/questions/24954974/import-error-for-oauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!