WordsAPI

FREEMIUM
Verified
By dpventures | Updated 8일 전 | Data
Popularity

9.9 / 10

Latency

193ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Missing Mashable Key

Rapid account: Mike Anbplips
MikeAnbplips
8년 전

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년 전

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년 전

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.

Join in the discussion - add comment below:

Login / Signup to post new comments