Viktor Viktor -4 years ago 46
Python Question

Connecting to API, getting 409 back

I am completely new to APIs and I'm having a hard time connecting to Marvel API. Documentation says my connection link should be something like this:

hash is a md5 string containg from time stamp (or other string that would be changing every request, private key and public key)

I registered on their website and I have my keys, this is how I am trying to make a call to find Character who's name begins with "Spider"

Creating every request changing string:

t ='{:%H:%M:%S}'.format(
t = t.replace(":", "")

output: "213944"


m = hashlib.md5(t+private+public).hexdigest()

pack I am trying to use:

pack = '<ACTUAL-API-KEY>&hash=' + m

Requesting printing response:

response = requests.get(pack)

I keep getting back
and according to API documentation it means that I have wrong timestamp, public or private key. I spent hours already trying to find whats wrong and I need some help.

This is a direct link to API documentation

Answer Source

As per the documentation, you are missing the ts parameter. Add your t variable as the ts parameter.

pack = '<ACTUAL-API-KEY>&hash=' + m + '&ts=' +t

Also, the documentation states that ts to change on a request-by-request basis. Consider using t=str(int(time.time()*1000)) instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download