我的目标是将我从Restful api调用中提取的数据发布到我专门创建的主题,使消息显示每个键和值。
# PubSub Vars
project_id = os.environ.get('PROJECT_ID')
topic_name = os.environ.get('TOPIC_NAME')
c_tenant = os.environ['c_tenant']
tpsswd = os.environ['tpsswd']
c_user = os.environ['c_user']
tenant_id = os.environ['tenant_id']
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(project_id, topic_name)
def get_callback(f, data):
def callback(f):
try:
print(f.result())
futures.pop(data)
except: # noqa
print('Please handle {} for {}.'.format(f.exception(), data))
return callback
verify = True
url = 'https://%s/Redrock/query' % c_tenant
headers = {
'X-NATIVE-CLIENT': 'true',
'Content-Type': 'application/json',
'Authorization': 'Bearer %s' % bearer_token
}
r = requests.get(url, json={"script": "@/lib/server_user_activity.js"}, headers=headers, verify = verify)
response = json.loads(r)
traffic = json.dumps(response)
if r.status_code == requests.codes.ok:
for item in traffic.items:
Jsonresponse = publisher.publish(topic_path,data =)
print(key + ':' + value)
Here is the documentation I am following (来自Google),但由于我没有看到发布到我的主题的任何数据,因此我对此并不完全理解。谁能引导我朝正确的方向前进?