0

In my program, I am trying to access https://api.dropbox.com/1/oauth2/token. In order to do that, I was trying to use http.client.HTTPSConnection(). However, I am receiving a 400 statement from the server, even though when I send the same request through my browser, I get an actual response:

{"error": "Call requires one of the following methods: POST, OPTIONS. Got GET."}

I believe that this happens for subdomains, since I also tested the function for https://docs.python.org/3/, and the result is very similar.

Here is my code (Python3):

conn = http.client.HTTPSConnection('docs.python.org')
conn.request('get', '/3/')
response = conn.getresponse().read()
print(response)

How should I use the http.client library to send the proper request?

3
  • 2
    Try use an uppercase 'GET'? Commented Oct 14, 2016 at 6:08
  • @Philip Tzou I can't believe this actually fixed it! Please post is an answer so I can accept it Commented Oct 14, 2016 at 15:27
  • Might be worth to look at requests Commented Oct 15, 2016 at 21:11

1 Answer 1

2

TL;DR: Change the lowercase 'get' to uppercase 'GET' should resolve the problem.

The reason: according to section 5.1.1, RFC2616:

The Method token indicates the method to be performed on the resource identified by the Request-URI. The method is case-sensitive.

RFC2616 also defined 8 methods which are "OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", and "CONNECT". All of them are uppercase.

We do know some HTTP clients like python-requests and jQuery.ajax also support lowercase methods but they are just not the standard way defined by the RFC for using those methods. To prevent issues, use uppercase ones first.

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

1 Comment

requests would be a more relevant lowercase example since this is a python question

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.