Google Ads cannot create refresh token

357 views
Skip to first unread message

Oliver

unread,
Mar 7, 2022, 12:07:24 PM3/7/22
to Google Ads API and AdWords API Forum
Hi,

I've been creating refresh tokens successfully for some time now, but suddenly it doesn't work, even though I'm using the same code.

This issue is similar to https://groups.google.com/g/adwords-api/c/xEWD6khWmcI/m/_jjTxl3uAgAJ?pli=1 but seeing as there was no solution there other than "use a different computer" or "reinstall your OS", I'm posting again as neither of those suggestions are particularly suitable for me.

I'm using the Python client library locally (https://developers.google.com/google-ads/api/docs/client-libs)

I'm calling authenticate-in-web-application.py. It gets as far as opening the browser: http://localhost:8080 but when it opens I get the following error message:

----
Waiting for authorization and callback to: http://localhost:8080...
Traceback (most recent call last):
  File "/home/.../authenticate_in_web_application.py", line 203, in <module>
    main(args.client_secrets_path, configured_scopes)
  File "/home/.../authenticate_in_web_application.py", line 81, in main
    code = _get_authorization_code(passthrough_val)
  File "/home/.../authenticate_in_web_application.py", line 112, in _get_authorization_code
    params = _parse_raw_query_params(data)
  File "/home/.../authenticate_in_web_application.py", line 160, in _parse_raw_query_params
    params = match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

---

On line 157 of the above file, inside the _parse_raw_query_params(data) function there is this line:

decoded = data.decode("utf-8")

The variable 'decoded' at this point contains the following:

GET / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Linux"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8


Seems like there should be some args with the GET on the first line?
The next 2 lines are:

match = re.search("GET\s\/\?(.*) ", decoded)
params = match.group(1) <-- Error here (match is 'NoneType')

I re-downloaded the client libaray, and created a fresh virtual environment, but nothing I've tried so far has helped, so if anyone has any ideas, I'd be very grateful!!

Python version is 3.9.10 (but this hasn't changed since it was working last week)

Oliver

Google Ads API Forum Advisor

unread,
Mar 8, 2022, 2:12:21 AM3/8/22
to oliver...@hallam.co.uk, adwor...@googlegroups.com
Hi Oliver,

Thank you for raising this concern to Google Ads Api Forum.
I see that the issue here is Python client library related. I would suggest to trying this guide that will walk you through how to set up OAuth2 for API access using your own credentials.Yet, if the error still occurs after trying this guide,you may directly reach out to the client library owner by filing an issue in the Issue tab of github.

Let us know if you have further questions.

Regards,
Google Logo
Carmela
Google Ads API Team
 

 

ref:_00D1U1174p._5004Q2XmAn3:ref
Reply all
Reply to author
Forward
0 new messages