0

私はスクリプトを書いていますが、指定された公開鍵でreCAPTCHAチャレンジを取得する必要があるので、これを次のように開いた場合は次のようになりますurllib2

chp = urllib.urlencode(dict({'k': key}))
chg = urllib2.urlopen('http://www.google.com/recaptcha/api/challenge', chp).read()

その後、そこからチャレンジを取得して返すことができますが、これを行うとエラーが発生します。

urllib2.HTTPError: HTTP Error 405: HTTP method POST is not supported by this URL

どうすればこれを解決できますか?

4

1 に答える 1

0

Use a GET request instead:

chp = urllib.urlencode(dict({'k': key}))
chg = urllib2.urlopen('http://www.google.com/recaptcha/api/challenge?' + chp).read()

As the urllib2 documentation states:

data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided.

You were passing in chp as POST data by passing it to the urlopen method as the second positional argument. Concatenating it to the URL with a ? instead makes it a GET request.

于 2012-06-12T15:38:57.533 に答える