WordsAPI

FREEMIUM
Verified
โœ“
Door dpventures | Bijgewerkt vor 21 Tagen | Data
Populariteit

9.9 / 10

Latency

181ms

Serviceniveau

100%

Health Check

N/A

Terug naar alle discussies

Missing Mashable Key

Rapid account: Mike Anbplips
MikeAnbplips
8 years ago

Hi,

I subscribed and my queries work from the web interface.

I am also aware that the field โ€œX-Mashape-Keyโ€ contains my key.

I use Python3 for my application.

Since neither unirest nor the wordsapi libraries seem to work with Python3, I need to create my query on my own.

Taking the โ€œalsoโ€ example, I would imagine that Iโ€™d have to build something like that:

https://wordsapiv1.p.mashape.com/words/{my_word_here}/also&X-Mashape-Key=my_key_here&Accept=application/json

However, pasting this into the browser does not work: I get the following response:

{"message":"Missing Mashape application key. Go to http:\\/\\/docs.mashape.com\\/api-keys to learn how to get your API application key."}

So it seems that it is not understanding where to find the key.

Can you help me with that?

Ultimately, I plan to use Python module requests for this, since as said the other interfaces/libs do not seem suitable at the moment.

I would then do something along these lines:

import requests

headers={ "X-Mashape-Key": "my_key_here",  "Accept": "application/json" }

r = requests.get('https://entry_point', params=headers)

But that - again like in the case of copy paste into browser - gives the exact same response of โ€œno keyโ€โ€ฆ

Rapid account: Mike Anbplips
MikeAnbplips Commented 8 years ago

Thanks.
I am new to HTTP and the only way Iโ€™ve ever used an API was by setting up a long string with a website address, my query, and the key.
The way your API works is different as you say, so I understand I cannot just build a long simple string to make this work.

Since you used the specific word headers once more, I got triggered and looked up some Python library that treats the HTTP protocol (which I know nothing of).

I found httplib2 : http://bitworking.org/projects/httplib2/doc/html/libhttplib2.html

Then my full code is:

    import httplib2
    
    hd = {'Accept': 'application/json','X-Mashape-Key': 'my_ultra_long_key'}
    endpoint = 'https://wordsapiv1.p.mashape.com/words/bump/also'
    resp, content = h.request(endpoint,"GET",headers = hd)

This works!! So the โ€œtrickโ€ is that one has to formulate a GET request using the https protocol, not just โ€œqueryโ€ a website.

Thank you for pointing me in the right direction! Hope this can help other people down the line.

Rapid account: Wordsapi
wordsapi Commented 8 years ago

Hi Mike,
The โ€˜X-Mashape-Keyโ€™ must be sent as an HTTP header, not as part of the query string (as youโ€™re doing in your first example).

Iโ€™m not familiar with Python, but your second example looks correct, in general. If you paste in the real code (without your read key) perhaps I can help more.

Doe mee aan de discussie - voeg hieronder een opmerking toe

Log in / Schrij u in om nieuwe opmerkingen te plaatsen