あいさつ!
私は、ファイル拡張子をフィルタリングしてファイルをアップロードするサービスを決定する、複数サービスのファイル アップローダーに取り組んできました。私の主なターゲットは、Imgur ユーザー アカウントへのアップロードです。その API は、他のサービス (つまり、OAuth2 による認証) とは対照的に最も複雑です。HTTPLib 証明書ストアが SSL ハンドシェイクを検証しないため、以前は SSL 経由で接続する際に問題がありましたが、手動で Imgur の証明書プロバイダーの CA を証明書リストに追加することで問題を解決しました。
とにかく、私は Cookie を使用して Imgur に「ログイン」できましたが、oauth を使用したいのですが、Cookie メソッドはまだアップロード制限が低い匿名 API を使用しています。Oauth 認証 URL を生成し、wxPython を使用して、ユーザーが資格情報を提供するときに、その URL で指定された PIN を要求する単純なテキスト入力ダイアログを作成することで、これを試みています。問題は、python-oauth2 のオーセンティケーターを呼び出すと、gzip の解凍エラーが発生することです。これに対処する方法がわかりません。エラーは次のとおりです。
Traceback (most recent call last):
File "C:\Users\Austin\Programming\python\uploaderator\mk2\main.py", line 10, in <module>
uploader = crumpet.Crumpet()
File "C:\Users\Austin\Programming\python\uploaderator\mk2\crumpet.py", line 30, in __init__
s.connect()
File "C:\Users\Austin\Programming\python\uploaderator\mk2\imgurHandler.py", line 40, in connect
self.authorize(pin)
File "C:\Users\Austin\Programming\python\uploaderator\mk2\oauthHandler.py", line 28, in authorize
resp, content = client.request(self.access_token_url, "POST")
File "build\bdist.win32\egg\oauth2\__init__.py", line 682, in request
File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 1436, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 1188, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 1174, in _conn_request
content = _decompressContent(response, content)
File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 384, in _decompressContent
content = gzip.GzipFile(fileobj=StringIO.StringIO(new_content)).read()
File "C:\Python27\lib\gzip.py", line 245, in read
self._read(readsize)
File "C:\Python27\lib\gzip.py", line 316, in _read
self._read_eof()
File "C:\Python27\lib\gzip.py", line 334, in _read_eof
crc32 = read32(self.fileobj)
File "C:\Python27\lib\gzip.py", line 25, in read32
return struct.unpack("<I", input.read(4))[0]
struct.error: unpack requires a string argument of length 4
ピンが取得された後に呼び出される私の承認関数は次のとおりです。
def authorize(self, pin):
self.token_u.set_verifier(pin)
client = oauth.Client(self.consumer, self.token_u)
resp, content = client.request(self.access_token_url, "POST")
access_token = dict(urlparse.parse_qsl(content))
self.oauth_token = access_token['oauth_token']
self.oauth_token_secret = access_token['oauth_token_secret']
self.token = oauth.Token(self.oauth_token, self.oauth_token_secret)
self.client = oauth.Client(self.consumer, self.token)
if resp['status'] == '200':
return True
else:
return False
self.access_token_url はhttps://api.imgur.com/oauth/access_tokenであり、Imgur API 認証リソースで指定されています。
これが私のコードの問題なのか、Imgur が応答で返すものの問題なのかはわかりません。非常によく似た方法を使用して正常に動作するように見える他の python ベースのアップローダがあるためです。タイトルで述べたように、私は Python 2.7 とpython-oauth2を使用しています。
ご意見をいただければ幸いです。お時間をいただきありがとうございます。
分度器忍者