Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将列表转换为Google发布/订阅的bytestring_Python_Python 3.x_Google Cloud Platform - Fatal编程技术网

Python 将列表转换为Google发布/订阅的bytestring

Python 将列表转换为Google发布/订阅的bytestring,python,python-3.x,google-cloud-platform,Python,Python 3.x,Google Cloud Platform,我在从python客户端向google云发布/订阅服务发布消息时遇到了一个问题 我有一个基于rest的公共API,它返回JSON数据。返回的数据是列表中的字典形式 我已经将字典中的值提取到一个列表中,并使用bytes()将其转换为bytestring,但是它仍然抛出下面的异常 ['EB'、'Pulaski'、'2018-03-06 21:50:18.0'、'0.5'、'41.7930671862'、'41.793140551'、'-87.7136071496'、'W'、'Central Park

我在从python客户端向google云发布/订阅服务发布消息时遇到了一个问题

我有一个基于rest的公共API,它返回JSON数据。返回的数据是列表中的字典形式

我已经将字典中的值提取到一个列表中,并使用bytes()将其转换为bytestring,但是它仍然抛出下面的异常

['EB'、'Pulaski'、'2018-03-06 21:50:18.0'、'0.5'、'41.7930671862'、'41.793140551'、'-87.7136071496'、'W'、'Central Park'、'-1'、'1'、'-87.7231602513'、'55']

response = requests.get("https://data.cityofchicago.org/resource/8v9j-bter.json")
traffic = response.json()


result_list = []
for d in traffic:
  result_list.append([v for k, v in d.items()])

for x in result_list:
  print(x)
  publisher.publish(topic_path, data = bytes(x))

看起来您应该使用x.encode('utf-8')而不是字节(x)来转换为ByTestString,根据这里的Python示例:

什么异常?pub/sub必须作为ByTestString发送