Search code examples
pythonjsonpython-requestsebay-api

Python Ebay SDK with URL JSON Object Must be a String Error


I'm making my first attempt at setting up my Python code for the eBay finding API and I'm stumped.

I haven't worked my way into printing or saving anything yet because the code won't run. I'm getting the following error:

"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""

My code so far: (I'm using the "URL" version of ebay's suggested methods)

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()

Solution

  • EbaySdk is not returning you that error.

    requests.get returns a Response object, not a string. json.loads requires string or bytes, but you gave it a Response.

    That Response object has its own json function

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