Using python requests to talk to the github api.
response = requests.post('https://api.github.com/orgs/orgname/repos', auth, data)
If the request returns a 405 error I get HTML in the response.text
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
</body>
</html>
If the request returns a 422 error I get JSON in the response.text
{"message":"Validation Failed","errors": [{"resource":"Repository","code":"custom","field":"name","message":"name already exists on this account"}],"documentation_url":"https://developer.github.com/v3/repos/#create"}
Can I force the API to only return JSON?
If not, can I find out what type the response content will be?
http response code!JSON, so in your case it may be an authentication issue - or in other words you are trying to retrievenot-allowedcontent and that is maybe why the server doesn't send a response back, instead prints a not allowed message inHTML...try: json.loads()and then except with html.