Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding error using google adwords api

I am using the google adwords api. Currenlty my only code is:

from googleads import adwords
adwords_client = adwords.AdWordsClient.LoadFromStorage()

This results in an error displaying Your default encoding, cp1252, is not UTF-8. Please run this script with UTF-8 encoding to avoid errors.

I am using Python 3.6, which should be UTF-8 by default. What is the source of this error/how is it avoided?

like image 754
kyrenia Avatar asked Jul 15 '17 20:07

kyrenia


2 Answers

It turns out that this is actually a warning emitted by googleads whenever the default encoding returned by locale.getdefaultlocale() is not UTF-8.

If your script runs without issues, I feel that you can safely ignore it. Otherwise it might be worth a try to set a different locale at the beginning of your code:

import locale
locale.setlocale(locale.LC_ALL, NEW_LOCALE)

I take it that you are running Windows, so I'm not sure what the proper locale definitions are. On Linux, you could use en_US.UTF-8, but that's probably not going to work for you.

like image 118
dorian Avatar answered Nov 03 '22 17:11

dorian


Try importing the _locale module.

import _locale

_locale._getdefaultlocale = (lambda *args: ['en_US', 'UTF-8'])

like image 2
Hardik Patel Avatar answered Nov 03 '22 18:11

Hardik Patel