0

以下の Python コードを Web サービスに使用しましたが、ここではサイトの URL に https が含まれています。httpを使用すると、Webサービスの実行時に「メソッドが見つかりません」というエラーが発生し、httpsを使用すると、このコードは機能しません。

httpsでこの問題を解決する方法を教えてください。

import urllib
uid = username
pwd = psw   
params = urllib.urlencode({
    'uid': uid,
    'pwd': pwd,
data = urllib.urlopen(url, params).read()
print data

または、Web サービスを使用できる他の方法を教えてください。

前もって感謝します!!!

4

1 に答える 1

0

映画監督は権利を持っています。リクエストを使用してみてください。関数の例:

def http_get(url, user=None, password=None, proxies=None, valid_response_status[httplib.OK], **kwargs):
"""
Performs a http get over an url
@param url: the url to perfom get against
@type url: str
@param user: user if authentication required
@type user: str
@param password: password if authentication required
@type password: str
@param proxies: proxies if required
@type proxies: dict
@param valid_response_status: http response status code considered as valid
@type valid_response_status: list of int
@raise exception: if the response status code is not in valid_response_status list
"""
auth = HTTPBasicAuth(username=user, password=password)
kwargs['proxies'] = proxies
kwargs['auth'] = auth
try:
    LOGGER.debug("Performing http get over : %s" % url)
    _request = requests.get(url, **kwargs)
    if _request.status_code not in valid_response_status:
        http_error_msg = '%s Error: %s' % (_request.status_code, _request.reason)
        http_error = HTTPError(http_error_msg)
        http_error.response = _request
        raise http_error
    return _request.content
except:
    LOGGER.error("Error while performing http get over : %s" % url)
    raise
于 2013-08-30T13:06:29.723 に答える