【问题标题】:Python Ebay SDK with URL JSON Object Must be a String Error带有 URL JSON 对象的 Python Ebay SDK 必须是字符串错误
【发布时间】:2018-07-24 04:03:40
【问题描述】:

我第一次尝试为 eBay 查找 API 设置我的 Python 代码,但我被难住了。

我还没有打印或保存任何内容,因为代码无法运行。我收到以下错误:

"file: "C:\Users\juan\Anaconda3\lib\json\_init_.py", line 348, in loads
'not {!r}'.format(s._class_._name_))
typeError: the JSON object must be str, bytes or bytearry, not "Response""

到目前为止我的代码:(我使用的是 ebay 建议方法的“URL”版本)

from ebaysdk.finding import Connection as finding
from bs4 import BeautifulSoup
import json
import requests

url = "http://svcs.ebay.com/services/search/FindingService/v1\
?OPERATION-NAME=findCompletedItems&\
SERVICE-VERSION=1.7.0&\
SECURITY-APPNAME=12221222-121212121-111-11111111-111111111&\
RESPONSE-DATA-FORMAT=JSON&\
REST-PAYLOAD&\
GLOBAL-ID=EBAY-MOTOR&\
keywords=Garmin+nuvi+1300+Automotive+GPS+Receiver&\
categoryId=156955&\
itemFilter(0).name=Condition&\
itemFilter(0).value=3000&\
itemFilter(1).name=FreeShippingOnly&\
itemFilter(1).value=true&\
itemFilter(2).name=SoldItemsOnly&\
itemFilter(2).value=true&\
sortOrder=PricePlusShippingLowest&\
paginationInput.entriesPerPage=2"

info = requests.get(url)
doc = json.loads(info).decode()

【问题讨论】:

    标签: python json python-requests ebay-api


    【解决方案1】:

    EbaySdk 不会向您返回该错误。

    requests.get 返回一个响应对象,而不是一个字符串。 json.loads 需要字符串或字节,但你给了它一个响应。

    那个Response对象有自己的json函数

    info = requests.get(url)
    doc = info.json()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-26
      • 1970-01-01
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2021-02-27
      • 1970-01-01
      相关资源
      最近更新 更多