【发布时间】:2015-06-22 20:37:45
【问题描述】:
我正在尝试获取“id”号码,然后在程序中使用它。如果重要,响应是 .json
{"run_at":1818086502,"quantity":295092,"queue":"units","original_duration":388900193,"duration":388900193,"unit_type":"Harrier","city_id":1102142875,"id":3720348749},"success":true}}
这是“id”所在的响应的一部分。
这就是我目前所拥有的:
cadena= "Draoumculiasis" + params + "LandCrocodile" + url + "Bevar-Asp"
cadenau=cadena.encode('utf8')
m=hashlib.sha1(cadenau)
xs3=m.hexdigest()
headers= { 'Host': realm , 'Connection': 'keep-alive', 'Content-Length': len(params), 'Origin': 'http://castlemania-production.s3.amazonaws.com', 'x-s3-aws': xs3, 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11', 'content-type': 'application/x-www-form-urlencoded', 'Accept': '*/*', 'Accept-Encoding': 'gzip,deflate,sdch', 'Accept-Language': 'es-ES,es;q=0.8', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'DNT': 1, 'Cookie': cookie }
conn=http.client.HTTPConnection(realm,80)
conn.request("POST",url,params, headers)
response=conn.getresponse()
ID 每次都会改变。
我已经制作了制作 id 和使用 id 的部分,我需要连接这两者而无需手动输入。 可悲的是,我不是程序员,所以如果可能的话,我正在寻找完整的解决方案。我做了一些研究,但无法弄清楚。
更新 1
正如戈德的回答中所建议的那样,我使用
responseData = response.read().decode('utf-8')
items = json.loads(responseData)
现在我得到了错误
Traceback (most recent call last):
File "N:\Files\doa\Py's\testinggettingid.py", line 54, in <module>
items = json.loads(responseData)
File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line1 column 1 (char 0)
更新 2 我已经通过
删除了错误 response=conn.getresponse()
responseData = response.read().decode('utf-8')
print(responseData)
items = json.loads(responseData)
idValue = items['id']
print(idValue)
但它显示的是我的玩家 ID 而不是工作 ID。
更新 3
按要求打印(response.getheaders())
【问题讨论】:
-
“我不是程序员,所以如果可能的话我正在寻找完整的解决方案” - 这不是代码编写服务;如果您需要开发人员,请雇用一位。但请注意,代码和 JSON 数据都是文本 - 为什么您将它们作为场外屏幕截图提供?!
-
我在 URL 中看不到
id。请不要链接到屏幕截图。包括图片或代码。 -
请edit您的问题包括代码和/或示例数据作为文本。屏幕截图不是很有帮助(尤其是当它们发布在显然需要 Flash 的充满广告的网站上时)。
-
抱歉,第一次发帖。已编辑,如果我知道开发人员,我会雇用它 ^^ 我怀疑这对有经验的人来说很难,但对我来说是这样。
-
您的 JSON 格式无效