Network Service has is not JSON serializable issue
@christopherseeley 已经在做这个了。
开始于 2019年3月14日。
评估
这个 Issue 还没有评估数据。
描述
I went from googleads 10 to the newest version of ad manager and now a simple get of all networks associated with a service email account does not work anymore. I get a serialization error with the response. This was not an issue before upgrading. If I downgrade again everything goes back to normal. Is there something I need to do? I've even printed the entire object I'm attempting the json.dumps on and if I copy that into a new script and place it into a json.dumps function it works so there doesn't appear to be anything wrong with the list I'm passing in. This also make it very hard to debug this issue.
Error:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default raise TypeError(repr(o) + " is not JSON serializable")
TypeError: {
'id': 604966L,
'displayName': None,
'networkCode': '203086286',
'propertyCode': 'ca-pub-3065783271784989',
'timeZone': 'Europe/Amsterdam',
'currencyCode': 'EUR',
'secondaryCurrencyCodes': [],
'effectiveRootAdUnitId': '202086406',
'isTest': False
} is not JSON serializable
import services
import json
import flask
from datetime import datetime, timedelta
from pytz import timezone
import pytz
from time import gmtime, strftime
from suds.sudsobject import asdict
NETWORK = ""
dfp = services.ad_manager
def recursive_asdict(data):
result = {}
for key, value in asdict(data).iteritems():
if hasattr(value, '__keylist__'):
result[key] = recursive_asdict(value)
elif isinstance(value, list):
result[key] = []
for item in value:
if hasattr(item, '__keylist__'):
result[key].append(recursive_asdict(item))
else:
result[key].append(item)
else:
result[key] = value
return result
def suds_to_json(data):
result = []
if(isinstance(data, list)):
for item in data:
if hasattr(item, '__keylist__'):
result.append(recursive_asdict(item))
else:
result.append(item)
return json.dumps(result)
return json.dumps(recursive_asdict(data))
def getNetworks():
return suds_to_json(services.NetworkService.getAllNetworks())
def connect(networkId, method, params=None):
global NETWORK
if (NETWORK != networkId):
services.connectToNetwork(networkId)
NETWORK = networkId
try:
if(params):
return method(params)
return method()
except Exception,e:
print e
if hasattr(e, 'fault'):
return suds_to_json(e.fault), 400
else:
return e, 500
services.py
import credentials
from googleads import ad_manager, oauth2
oauth2_client = oauth2.GoogleServiceAccountClient(credentials.KEY_FILE, oauth2.GetAPIScope('ad_manager'))
dfp_client = ad_manager.AdManagerClient(oauth2_client, credentials.APPLICATION_NAME)
NetworkService = dfp_client.GetService('NetworkService', version=credentials.API_VERSION)
def connectToNetwork(networkId):
global ReportService
client.network_code = networkId;
ReportService = client.GetDataDownloader(version=credentials.API_VERSION)
- 主要语言
- Python
- 星标
- 749
- 派生
- 967
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleads/googleads-python-lib 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 25/100
-
image-package 未关闭
难度 5/5 一周以上 新手友好度 10/100
-
难度 1/5 1 小时以内 新手友好度 1/100
查看 googleads/googleads-python-lib 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
anthropics/skills#1811 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
speaches-ai/speaches#678 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
datalayer/mcp-compose#42 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
conda-forge/spacy-feedstock#177 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
UKGovernmentBEIS/inspect_evals#2523 ·