How to import Product API on ebaysdk? - python

I am trying to find information (description, title, images, aspects, and basically everything) on a product by using a UPC. I managed to do so by using eBay's trading API (GetItem) and productID. However, when I am trying to do it with a UPC I encounter problems. There is not much instructions on the web. I found the function getProductDetails, which is supposed to answer my question:
This is my code:
from ebaysdk.trading import Connection
api = Connection(devid=dev_id, certid=cert_id, appid=app_id, token=token_id, globalId="EBAY-US", config_file=None)
response = api.execute('getProductDetails', {"productDetailsRequest": {"dataset": {"UPC": "#UPCNUMBER"}}})
r = response.dict()
print(r)
However, when I tried to use the same API (trading) I got this error:
ConnectionError: 'getProductDetails: Class: RequestError, Severity: Error, Code: 2, Unsupported API call. The API call "getProductDetails" is invalid or not supported in this release.'
I tried to understand what API exactly I should use, but there is no information on the internet. From the documentation, I can understand that that is a Product API. However, when looking at the different ebaysdk.xxx sub-modules, I don't see any sub-module which fits.
Does somebody know anything about this?

Related

Why does OpenStreetMap give a 403 error through Python's urllib.request.urlretrieve, but works perfectly when using Requests?

I'm trying to grab tiles from OpenStreetMap. I learned the syntax of their API. I have an "old way" of doing things, using Requests, and a "new way", which is being used by someone else's github project. I'm trying to use their project, but it's failing for me in one spot. I then put together this short script as a minimal example:
from PIL import Image
import requests
import urllib.request
#A tile we want to grab from Open Street Map
tile_url = "https://a.tile.openstreetmap.org/16/19299/24629.png"
#Old way: Get the bytes via requests.get, then parse as image and save.
old_way = Image.open(requests.get(tile_url,stream=True).raw)
old_way.save("oldway.png")
#New way: use urlretrieve to directly copy the file over to newway.png
destination = "newway.png"
try:
path, response = urllib.request.urlretrieve(tile_url, destination)
except urllib.error.URLError as e:
print("URL error!")
print(e.code)
#Expected behavior: Two identical images are created,
#named oldway.png and newway.png
#Actual behavior: We get oldway, but newway gives a 403 error.
What's going wrong here? What's the difference between these two HTTP GET requests which results in the first one working fine, and the second one giving a 403 error? I've tried digging into the source code of the respective Python libraries, but it turns out to be a pretty long mess of functions calling each other. And of course since it's HTTPS, I can't monitor the network connection to evaluate the raw bytes being transferred and figure things out that way.
Is there something wrong with the user-agent? Something with the headers? Please note that I'm not just trying to solve this problem ("What's the issue? You have a method that works. Ignore the broken one"), but I'm trying to learn about the details here and hoping that this odd edge case can benefit me in the future.

Google PageSpeed Score Calculation

I am trying to include the Google PageSpeed Insights Score in my application. I came across the api for it and have tried to use it:
https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=http://wikipedia.org&filter_third_party_resources=true&locale=en_US&screenshot=false&strategy=desktop&key=MyAPIKey
After this I got the output as shown in the gist:
https://gist.github.com/JafferWilson/6f8c5661e11654f301247edca45d23df
But when I use the application of PageSpeed Insights, with same domain as : WikiPedia.org, I got different result of score and could not find that in the JSON api: https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fwikipedia.org&tab=mobile
I am using Python2.7 with windows10. and have tried this code for accessing the api:
>>> url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=http://wikipedia.org&filter_third_party_resources=true&locale=en_US&screenshot=false&strategy=desktop&key=MYAPIKey"
>>> response = urllib.urlopen(url)
>>> data = json.loads(response.read())
print data.
But I want to have the exact scoring as shown on the PageSpeedInsights of Google. Kindly suggest me what is the way to have the same score as that of Google Insights Page. I could not see the same score in the API result anyways.
For Desktop/Mobile: set strategy=desktop to strategy=mobile in the url.
Discrepancies between the JSON and the website could possibly just be variation within multiple runs, since it's likely the website doesn't fall squarely within scoring buckets. However, it seems that the score is relatively stable within a 1-score range for both desktop and mobile.

Python Amazon Simple Product API: 400 Bad Request

So I read a couple of posts already regarding this topic and tried some things they mentioned to do to no avail. I am fairly certain I have correctly given my account permission to API calls, but that wasn't the problem. I saw something about signing a request to an AWS search, but I'm not quite sure if that's it or how I would even do it.
This is the code I have.
from amazon.api import AmazonAPI
def get_amazon_link(item):
amazon = AmazonAPI('...AmazonKey', '...SecretKey', '...AssociateTag')
try:
product = amazon.lookup(ItemId='B00GDQ0RMG')
except Exception as e:
print e
print product
Right now the item I'm passing the function is hard coded just to try and get it working. If anyone could help me out that would be awesome.
Make sure you pass the correct region for which your account is registered. More info here.

How to use the AlchemyAPI for face detection / recognition in Python

This is pretty much a generic question and just would like someone to point me the right direction. I understand the existence of an API in Alchemy as documented in :http://www.alchemyapi.com/api/image-tagging/urls.html?__hstc=27013730.9b40428638d250ef6490e695d551207d.1458459083806.1458459083806.1458459083806.1&__hssc=27013730.1.1458459083807&__hsfp=2749035364
I have managed to call the API but unable to make any sense out of the data. My code thus far is as below :
import requests
apikey = "01405e7492ca333c6ab3a5c7da544e9f11bf6e26"
picture = open('IMG_1172.JPG','rb').read()
url="http://gateway-a.watsonplatform.net/calls/image/ImageGetRankedImageKeywords?apikey=01405e7492ca333c6ab3a5c7da544e9f11bf6e26&outputMode=json&forceShowAll=1"
r = requests.post(url = url, data = picture)
print r.txt
The above r.txt was unable to be executed as it shows Response 200. I was suppose to receive a json file back from my API call but I don't see it here.
Appreciate if anyone could guide me on this. Thanks !

Python Amazon Product Api not able to get image

I'm using python amazon product api and I can't seem to get the url for the image of the product.
Here is my code so far
for book in amz_api.item_search('Books', Keywords='cookies', ResponseGroup='Large', limit=10):
print book.ItemAttributes.Large
But I get this reply
AttributeError: no such child: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}Large
Any help would be apprecicated
To access the image URLs, you can try to change your code to use one of the following:
print book.SmallImage.URL
print book.MediumImage.URL
print book.LargeImage.URL
The error is because there is no "Large" attribute in ItemAttributes. The image URLs are available in a different part of the response.
The Large Response Group (ResponseGroup='Large') returns a lot of data. According to the docs it's for demonstration purposes and not intended for production applications. To make your code production ready, you might need a different approach, such as the Images Response Group (ResponseGroup='Images').
Also, the python type for the book variable in the above code is:
<type 'lxml.objectify.ObjectifiedElement'>
While debugging, you can look at all the data available in book using something like this:
from lxml import objectify
print(objectify.dump(book))

Categories

Resources