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 !
Related
I'm using https://developers.looker.com/api/explorer/4.0/methods/Query/query
Not entirely sure how some looks get a complete/incomplete response from the API, does anyone have experience working with looker API? want to understand what possible reasons could have led to this behaviour
incomplete response for look_id_1 : {"id":"1"}
complete response for look_id_2 : {"id":"2","view":"x","fields":["a"]}
Note - https://developers.looker.com/api/explorer/4.0/methods/Look/search_looks for the above looks retrieves complete information. I need the query response for the looks.
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.
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?
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.
I am using flask with python 3.5 and try to test my code with pytest for uploading the image.I have gone through various answers but sadly couldn't get the point to solve my problem.In link of github, it explains how to use filename, file_field
https://gist.github.com/DazWorrall/1779861
I tried in that way also but i wasn't going in right direction. Please help me in solving my problem. Here, post method is used to upload the image, content-part should be multi-part but regarding data, how to send the image data and its path.
test_client.post(
'/uploadimage',
content_type='multipart/form-data',
buffered=True,
data=dict(
file='user4.jpg', file_field=io.BytesIO(b"~/Downloads/images/")),
follow_redirects=True)
In here, while running for pytest it doesn't recognise the file. Dont know why? I will hope to get my answer soon.. Thanks.
res = test_client.post(
products_url,
content_type='multipart/form-data',
buffered=True,
data={
'file': (io.BytesIO(b'~/Downloads/images'), 'user4.jpg'),
})
Little bit change the way data is send.
It is working fine for me.