- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在请求后调用的文件中使用 JSON 文件。这不起作用,我得到的错误是:
ValueError: too many values to unpack
这是我的代码:
import requests
import json
def post_to_api(self, spider):
url = 'http://106309.nitrousapp.com:3000/api/v1/imports/batch_create'
headers = {'X-Api-Key': 'TOHhsxPyJnpZcUhLMMqj0XwipSY48PQxCXzIsW8FFpMt', 'Content-Type': 'application/json'}
r = requests.post(url, files=open('items.json', 'r'), headers=headers)
print r.json
这是完整的回溯:
Traceback (most recent call last):
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 150, in maybeDeferred
result = f(*args, **kw)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/scrapy/xlib/pydispatch/robustapply.py", line 57, in robustApply
return receiver(*arguments, **named)
File "/home/nitrous/code/trendomine/fancy/fancy/pipelines.py", line 41, in spider_closed
self.post_to_api(spider)
File "/home/nitrous/code/trendomine/fancy/fancy/pipelines.py", line 15, in post_to_api
r = requests.post(url, files=open('%s_items.json' % spider.name, 'r'), headers=headers)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/api.py", line 109, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/sessions.py", line 454, in request
prep = self.prepare_request(req)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/sessions.py", line 388, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/models.py", line 296, in prepare
self.prepare_body(data, files, json)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/models.py", line 444, in prepare_body
(body, content_type) = self._encode_files(files, data)
File "/home/nitrous/code/trendomine/local/lib/python2.7/site-packages/requests/models.py", line 132, in _encode_files
for (k, v) in files:
ValueError: too many values to unpack
我的 JSON 文件非常标准,并且格式正确。这是一个例子:
{
"product":[{"name": "A.P.C. Locker Hoody (Dark Navy)", "country": "USA", "price": "215", "category_old": null, "image_url": "http://thingd-media-ec6.thefancy.com/default/1011706283071373547_87a8a65d3b2a.jpg", "interest": "1", "link": "https://fancy.com/things/1011706283071373547/A.P.C.-Locker-Hoody-(Dark-Navy)", "company": "Fancy"},
{"name": "Darth Vader's Lightsaber MimoPowerTube2 Star Wars Series", "country": "USA", "price": "30", "category_old": null, "image_url": "http://thingd-media-ec1.thefancy.com/default/1011467404649176319_e719110203ae.jpg", "interest": "3", "link": "https://fancy.com/things/1011467404649176319/Darth-Vader's-Lightsaber-MimoPowerTube2-Star-Wars-Series", "company": "Fancy"},
{"name": "Boba Fett MimoPowerTube2 Star Wars Series", "country": "USA", "price": "30", "category_old": null, "image_url": "http://thingd-media-ec3.thefancy.com/default/1011472861069581593_f2390073e692.jpg", "interest": "2", "link": "https://fancy.com/things/1011472861069581593/Boba-Fett-MimoPowerTube2-Star-Wars-Series", "company": "Fancy"},
{"name": "Funko POP! Iron Man Ceramic Mug", "country": "USA", "price": "17", "category_old": null, "image_url": "http://thingd-media-ec4.thefancy.com/default/1011471256807021839_7b11976ede50.jpg", "interest": "1", "link": "https://fancy.com/things/1011471256807021839/Funko-POP!-Iron-Man-Ceramic-Mug", "company": "Fancy"},
{"name": "Charcoal Boiled Wool Sweatpant by Apolis", "country": "USA", "price": "248", "category_old": "Men", "image_url": "http://thingd-media-ec1.thefancy.com/default/986743205628222511_1853b853a79b.jpg", "interest": "2", "link": "https://fancy.com/things/986743205628222511/Charcoal-Boiled-Wool-Sweatpant-by-Apolis", "company": "Fancy"},
{"name": "Khaki Convertible Backpack by Hex", "country": "USA", "price": "100", "category_old": "Men", "image_url": "http://thingd-media-ec3.thefancy.com/default/986174222386597367_42a175cb4c86.jpg", "interest": "4", "link": "https://fancy.com/things/986174222386597367/Khaki-Convertible-Backpack-by-Hex", "company": "Fancy"},
{"name": "Funko POP! Hulk Ceramic Mug", "country": "USA", "price": "17", "category_old": null, "image_url": "http://thingd-media-ec1.thefancy.com/default/1011471115609971981_831322b6e212.jpg", "interest": "None", "link": "https://fancy.com/things/1011471115609971981/Funko-POP!-Hulk-Ceramic-Mug", "company": "Fancy"},
{"name": "Coolest Cooler", "country": "USA", "price": "485", "category_old": "Food", "image_url": "http://thingd-media-ec3.thefancy.com/default/671492680575882582_be703be1c98c.jpg", "interest": "139", "link": "https://fancy.com/things/671492680575882582/Coolest-Cooler-po", "company": "Fancy"},
{"name": "Funko POP! Spider-Man Ceramic Mug", "country": "USA", "price": "17", "category_old": null, "image_url": "http://thingd-media-ec4.thefancy.com/default/1011473609744456989_f62ee350ecbf.jpg", "interest": "1", "link": "https://fancy.com/things/1011473609744456989/Funko-POP!-Spider-Man-Ceramic-Mug", "company": "Fancy"},
{"name": "Funko POP! Spider-Man Salt & Pepper Shaker Set", "country": "USA", "price": "22", "category_old": null, "image_url": "http://thingd-media-ec1.thefancy.com/default/1011477384920046901_2a177ed28ef6.jpg", "interest": "None", "link": "https://fancy.com/things/1011477384920046901/Funko-POP!-Spider-Man-Salt-&-Pepper-Shaker-Set", "company": "Fancy"},
{"name": "Get Out Of My Life Tee", "country": "USA", "price": "37", "category_old": null, "image_url": "http://thingd-media-ec3.thefancy.com/default/1011529914114907917_071fb0dd5655.jpg", "interest": "1", "link": "https://fancy.com/things/1011529914114907917/Get-Out-Of-My-Life-Tee", "company": "Fancy"},
{"name": "Fur Real Greeting Card", "country": "USA", "price": "5", "category_old": null, "image_url": "http://thingd-media-ec5.thefancy.com/default/1011526354610429681_3718a08c1cd9.jpg", "interest": "2", "link": "https://fancy.com/things/1011526354610429681/Fur-Real-Greeting-Card", "company": "Fancy"},
{"name": "Geodesic Playhouse", "country": "USA", "price": "300", "category_old": "Kids", "image_url": "http://thingd-media-ec4.thefancy.com/default/955512370883461577_260ed730ea0e.jpg", "interest": "13", "link": "https://fancy.com/things/955512370883461577/Geodesic-Playhouse", "company": "Fancy"},
{"name": "Catnipped Tank Top", "country": "USA", "price": "24", "category_old": null, "image_url": "http://thingd-media-ec3.thefancy.com/default/1011535748509212461_e0ebf6f78f6a.jpg", "interest": "3", "link": "https://fancy.com/things/1011535748509212461/Catnipped-Tank-Top", "company": "Fancy"},
{"name": "Creep It Real Crewneck", "country": "USA", "price": "26", "category_old": null, "image_url": "http://thingd-media-ec3.thefancy.com/default/1011538479613484857_f4419054bbfa.jpg", "interest": "2", "link": "https://fancy.com/things/1011538479613484857/Creep-It-Real-Crewneck", "company": "Fancy"},
{"name": "Harvard Naw Crewneck", "country": "USA", "price": "50", "category_old": null, "image_url": "http://thingd-media-ec6.thefancy.com/default/1011555628595814261_0e08275d489e.jpg", "interest": "2", "link": "https://fancy.com/things/1011555628595814261/Harvard-Naw-Crewneck", "company": "Fancy"},
{"name": "QBracelet Smartphone Charger", "country": "USA", "price": "110", "category_old": "Gadgets", "image_url": "http://thingd-media-ec2.thefancy.com/default/698272167082598052_01939a626fe5.jpg", "interest": "18", "link": "https://fancy.com/things/698272167082598052/QBracelet-Smartphone-Charger-po", "company": "Fancy"},
{"name": "F*ck Off Crop Tank", "country": "USA", "price": "30", "category_old": null, "image_url": "http://thingd-media-ec3.thefancy.com/default/1011572077062266779_84283d6694da.jpg", "interest": "1", "link": "https://fancy.com/things/1011572077062266779/F*ck-Off-Crop-Tank", "company": "Fancy"},
{"name": "Black Cat-O-Lantern Tee", "country": "USA", "price": "35", "category_old": null, "image_url": "http://thingd-media-ec2.thefancy.com/default/1011559329523834755_0c5541944a26.jpg", "interest": "1", "link": "https://fancy.com/things/1011559329523834755/Black-Cat-O-Lantern-Tee", "company": "Fancy"},
{"name": "Monday Blues Ringer Tee", "country": "USA", "price": "42", "category_old": null, "image_url": "http://thingd-media-ec1.thefancy.com/default/1011544620326199127_9d35a8431b9b.jpg", "interest": "1", "link": "https://fancy.com/things/1011544620326199127/Monday-Blues-Ringer-Tee", "company": "Fancy"},
{"name": "Pinemeowpple Crop Top", "country": "USA", "price": "26", "category_old": null, "image_url": "http://thingd-media-ec4.thefancy.com/default/1011563553640947595_83b04d570969.jpg", "interest": "5", "link": "https://fancy.com/things/1011563553640947595/Pinemeowpple-Crop-Top", "company": "Fancy"},
{"name": "Gasometro Ring", "country": "USA", "price": "199", "category_old": "Women", "image_url": "http://thingd-media-ec5.thefancy.com/default/1011573460410834847_1420988eda40.jpg", "interest": "2", "link": "https://fancy.com/things/1011573460410834847/Gasometro-Ring", "company": "Fancy"},
{"name": "Matit\u00e0 Coat Rack", "country": "USA", "price": "199", "category_old": "Home", "image_url": "http://thingd-media-ec2.thefancy.com/default/1011576991335325607_5aebe93b44ec.jpg", "interest": "4", "link": "https://fancy.com/things/1011576991335325607/Matit%C3%A0-Coat-Rack", "company": "Fancy"},
{"name": "Mystical Fire Colorant", "country": "USA", "price": "75", "category_old": "Sports & Outdoors", "image_url": "http://thingd-media-ec1.thefancy.com/default/701418813568058872_5171d5c216c7.jpg", "interest": "113", "link": "https://fancy.com/things/701418813568058872/Mystical-Fire-Colorant", "company": "Fancy"}]}
最佳答案
关于python - 值错误: too many values to unpack with JSON File and Requests Post Call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33383102/
最近开始学习MongoDB。今天老师教了我们 mongoexport 命令。在练习时,我遇到了一个典型的问题,包括教练在内的其他同学都没有遇到过。我在我的 Windows 10 机器上使用 Mongo
我是 JSON Schema 的新手,读过什么是 JSON Schema 等等。但我不知道如何将 JSON Schema 链接到 JSON 以针对该 JSON Schema 进行验证。谁能解释一下?
在 xml 中,我可以在另一个 xml 文件中包含一个文件并使用它。如果您的软件从 xml 获取配置文件但没有任何方法来分离配置,如 apache/ngnix(nginx.conf - site-av
我有一个 JSON 对象,其中包含一个本身是 JSON 对象的字符串。我如何反序列化它? 我希望能够做类似的事情: #[derive(Deserialize)] struct B { c: S
考虑以下 JSON { "a": "{\"b\": 12, \"c\": \"test\"}" } 我想定义一个泛型读取 Reads[Outer[T]]对于这种序列化的 Json import
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve
我的旧项目在 MySQL 中有 Standard JSON 格式的数据。 对于我在 JS (Node.js) 和 DynamoDB 中的全新项目,关于 Standard JSON格式: 是否建议将其转
JSON 值字符串、数字、true、false、null 是否是有效的 JSON? 即,是 true 一个有效的 JSON 文档?还是必须是数组/对象? 一些验证器接受这个(例如 http://jso
我有一个 JSON 字符串,其中一个字段是文本字段。这个文本字段可以包含用户在 UI 中输入的文本,如果他们输入的文本是 JSON 文本,也许是为了说明一些编码,我需要对他们的文本进行编码,以便它不会
我正在通过 IBM MQ 调用处理数据,当由 ColdFusion 10 (10,0,11,285437) 序列化时,0 将作为 +0.0 返回,它会导致无效的 JSON并且无法反序列化。 stPol
我正在从三个数组中生成一个散列,然后尝试构建一个 json。我通过 json object has array 成功了。 require 'json' A = [['A1', 'A2', 'A3'],
我从 API 接收 JSON,响应可以是 30 种类型之一。每种类型都有一组唯一的字段,但所有响应都有一个字段 type 说明它是哪种类型。 我的方法是使用serde .我为每种响应类型创建一个结构并
我正在下载一个 JSON 文件,我已将其检查为带有“https://jsonlint.com”的有效 JSON 到文档目录。然后我打开文件并再次检查,结果显示为无效的 JSON。这怎么可能????这是
我正在尝试根据从 API 接收到的数据动态创建一个 JSON 对象。 收到的示例数据:将数据解码到下面给出的 CiItems 结构中 { "class_name": "test", "
我想从字符串转换为对象。 来自 {"key1": "{\n \"key2\": \"value2\",\n \"key3\": {\n \"key4\": \"value4\"\n }\n
目前我正在使用以下代码将嵌套的 json 转换为扁平化的 json: import ( "fmt" "github.com/nytlabs/gojsonexplode" ) func
我有一个使用来自第三方 API 的数据的应用程序。我需要将 json 解码为一个结构,这需要该结构具有“传入”json 字段的 json 标签。传出的 json 字段具有不同的命名约定,因此我需要不同
我想使用 JSON 架构来验证某些值。我有两个对象,称它们为 trackedItems 和 trackedItemGroups。 trackedItemGroups 是组名称和 trackedItem
考虑以下案例类模式, case class Y (a: String, b: String) case class X (dummy: String, b: Y) 字段b是可选的,我的一些数据集没有字
我正在存储 cat ~/path/to/file/blah | 的输出jq tojson 在一个变量中,稍后在带有 JSON 内容的 curl POST 中使用。它运作良好,但它删除了所有换行符。我知
我是一名优秀的程序员,十分优秀!