4

I'm trying to use the google people API to automate some contact creating on our Work Phones. But for using people API, I need to use OAuth 2, and I'm using the following code. I go to the authorization URL, get authorization response, but when I run the token line I get the error:

InsecureTransportError: (insecure_transport) OAuth 2 MUST utilize https.

The code is as follows:

import json
with open(r'C:\Users\Pedro\Desktop\client_id.json') as abb:
    ab = json.load(abb)



client_id = ab['installed']['client_id']
redirect_uri = ab['installed']['redirect_uris'][0]
client_secret = ab['installed']['client_secret']

from requests_oauthlib import OAuth2Session


scope = ['https://www.googleapis.com/auth/contacts']
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri,
                          scope=scope)
authorization_url, state = oauth.authorization_url(
        'https://accounts.google.com/o/oauth2/auth',
        # access_type and prompt are Google specific extra
        # parameters.
        access_type="offline", prompt="select_account")

#authorization_response = input('Enter the full callback URL')
authorization_response = r'RESPONSE'


token = oauth.fetch_token(
        'https://accounts.google.com/o/oauth2/token',
        authorization_response=authorization_response,
        # Google specific extra parameter used for client
        # authentication
        client_secret=client_secret,
        )

I think I all need to do is set up an https server? But I tried to find examples of OAuth2 servers, and all I got was people telling to disable the requirement for testing. I do not want to test, I want to run the OAuth so I can call requests on people API.

1 Answer 1

6

Try to shoot export OAUTHLIB_INSECURE_TRANSPORT=1in the terminal. It should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.