我正在尝试为DFP使用服务帐户,但我收到此错误
OpenSSL.crypto.Error:[('asn1 encoding routine','ASN1_D2I_READ_BIO','数据不够')]
我在dfp中添加了服务帐户,并检查了已创建的服务帐户的email_id,但仍然无法解决问题
这是我的代码,有人可以帮我解决这个问题
from googleads import dfp
from googleads import oauth2
import logging
logging.basicConfig(filename='debug.log',level=logging.DEBUG)
# OAuth 2.0 credential information. In a real application, you'd probably be
# pulling these values from a credential storage.
SERVICE_ACCOUNT_EMAIL = '600632524044-6g7l2njp5g5ldd21j7eaolf1k15pdm1u@developer.gserviceaccount.com'
KEY_FILE = 'D:\DFP\GoogleDFP.p12'
# DFP API information.
APPLICATION_NAME = 'New Srevice Account'
def main(service_account_email, key_file, application_name):
# with open(key_file, 'rb') as f:
# private_key = f.read()
# f.close()
oauth2_client = oauth2.GoogleServiceAccountClient(
oauth2.GetAPIScope('dfp'), service_account_email, key_file)
client = dfp.DfpClient(oauth2_client, application_name)
inventory_service = client.GetService('InventoryService', version='v201505')
statement = dfp.FilterStatement()
# Get ad units by statement.
while True:
response = inventory_service.getAdUnitsByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for ad_unit in response['results']:
print ('Ad unit with ID \'%s\' and name \'%s\' was found.'
% (ad_unit['id'], ad_unit['name']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
# networks = dfp_client.GetService('NetworkService').getAllNetworks()
# for network in networks:
# print ('Network with network code \'%s\' and display name \'%s\' was found.'
# % (network['networkCode'], network['displayName']))
if __name__ == '__main__':
main(SERVICE_ACCOUNT_EMAIL, KEY_FILE, APPLICATION_NAME)
答案 0 :(得分:0)
嘿,我收到错误,oauth2.py
中的googleads中有bug密钥文件应以二进制模式打开 oauth2.py中的第208行 open(key_file)为f:
它应该以open(key_file,' rb')作为f: