1
def thready(name,count):
    payload={'Accept': 'application/json;charset=utf-8', 'X-Mashape-Key': 'key'

            }


    link = "https://montanaflynn-gender-guesser.p.mashape.com/?name=" + name
    r=requests.get(link ,headers=payload)
    print r.headers
    data=r.json()

    print data


count=0

thready("bob",count)

So I just tried to do a simple HTTP request in python. In the r.header i get

{'date': 'Wed, 22 Jul 2015 06:30:12 GMT', 'content-length': '178', 'content-type
': 'text/html', 'connection': 'keep-alive', 'server': 'Mashape/5.0.6'}

In the header I said it should return json. The return is text though? Very confused about this fact? Some insight would be very helpful because I'm trying to do the simple

9
  • And what is your problem? As a result you gets JSON in string representation. Commented Jul 22, 2015 at 6:51
  • How do I work with it like a dictionary? Commented Jul 22, 2015 at 6:52
  • 1
    it is already a dictionary, but if you print the entire dict, it will look on the console almost like json. Just try print data['message'] Commented Jul 22, 2015 at 6:53
  • I cant even get paste the line of data Traceback (most recent call last): ValueError: No JSON object could be decoded Commented Jul 22, 2015 at 6:58
  • You should have written that fact in the question ;) For me the snippet works. Could you do print r.text and paste it here? Commented Jul 22, 2015 at 7:02

1 Answer 1

2

There is nothing wrong with the code.

I have inspected your API request upstream by going to the source: the API provider's page and it looks like the API is defunct/not working as expected. Which is exactly why you're getting errors. Solution: 1) Contact the provider to try to resolve the problem, its on them not on you to fix it 2) Find an alternative API from the same portal: https://www.mashape.com/explore?query=gender

Good luck

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, seems like it something on their side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.