1

I run this code

from oauthlib.oauth2 import BackendApplicationClient

from requests.auth import HTTPBasicAuth

import oauth2

import oauth

tokens_url = "https://x123.com/oauth/token"

client = BackendApplicationClient(client_id=client_id)

oauth = OAuth2Session(client=client)

token = oauth.fetch_token(token_url=tokens_url, client_id=client_id,

client_secret=client_secret)

and I get NameError: name 'OAuth2Session' is not defined

Cheetara
  • 95
  • 1
  • 12

1 Answers1

1

Try:

from requests_oauthlib import OAuth2Session

You may need to install requests_oauthlib using pip if it hasn't already been installed on your system.

David
  • 363
  • 3
  • 11
  • I tried that also, I get ImportError: No module named requests_oauthlib – Cheetara Feb 05 '18 at 11:19
  • You'll have to install that using pip – David Feb 05 '18 at 11:49
  • I don't have linux. Is there a way to install it on windows with pip? – Cheetara Feb 05 '18 at 12:05
  • Depending on your version of python, pip should be included by default. https://stackoverflow.com/questions/4750806/how-do-i-install-pip-on-windows – David Feb 05 '18 at 12:10
  • I did it and I get Traceback (most recent call last): File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main "__main__", fname, loader, pkg_name) File "c:\python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in File "c:\python27\pip.py", line 194, in main bootstrap(tmpdir=tmpdir) File "c:\python27\pip.py", line 83, in bootstrap from pip.commands.install import InstallCommand ImportError: No module named commands.install – Cheetara Feb 05 '18 at 12:18
  • @ David I only managed to install pip after installing python ver 3.6. and download the requests_oauthlib. It was impossible to install pip under python 2.7 on Windows 10. After that it worked. So if you like please edit and add to your answer that Windows users have to install pip and I will mark it as correct. Thank you for your time – Cheetara Feb 06 '18 at 08:00
  • @Cheetara Glad you got it working. I've added the additional instructions to my answer. – David Feb 06 '18 at 12:23