def post():
url = "someurl.com"
with open(jsonfile) as myfile:
for line in myfile:
post_fields = line
print(post_fields)
request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
post()
我正在尝试使用上面的代码将我的JSON数据发布到一个网站。然而,我遇到了一个错误。错误是
not a valid non-string sequence or mapping object
下面是我的JSON数据。你知道吗
[{"ContentUrl": "https://twitter.com/realDonaldTrump/status/871331574649901056", "Text": "Do you notice we are not having a gun debate right now? That's because they used knives and a truck!", "PublishDate": "4:43 AM - 4 Jun 2017", "Title": "", "SourceUrl": "https://twitter.com/@realDonaldTrump", "SocialNetwork": "Twitter", "Source": "", "Author": "Donald J. Trump", "Like_count": "147,875 likes", "Replies_count": "57,397 replies", "Retweets_count": "45,500 retweets", "Schema": "SOCIAL_MEDIA"}]
对我有什么帮助或建议吗?你知道吗
我试着把我在网上看到的方法结合起来,这对我来说终于奏效了。你知道吗
以下是我的意见:
json.loads
对每一行的json对象进行解码根据您对我问题的回答,json文件包含以下内容。你知道吗
那么,您希望在post请求中使用字典的哪个部分作为有效负载呢?你知道吗
这是固定密码。但是您仍然需要精确地确定要使用的
url
和payload
的正确位置。你知道吗相关问题 更多 >
编程相关推荐