24

GoogleAppEngineですばらしいリクエストライブラリを使用しようとしています。AppEngineと互換性のあるリクエストが依存するurllib3のパッチを見つけました。https://github.com/shazow/urllib3/issues/61

私はうまくいくことができます

import requests

しかしその後

response = requests.get('someurl')

次のトレースバックで失敗します。どうしたの?

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/admin/__init__.py", line 317, in post
    exec(compiled_code, globals())
  File "<string>", line 6, in <module>
  File "/Users/Rohan/Dropbox/MuktiTechnologiesINC/MuktiTechnologies/GAE/humanmictweet/GAE/libraries/requests/api.py", line 52, in get
    return request('get', url, **kwargs)
  File "/Users/Rohan/Dropbox/MuktiTechnologiesINC/MuktiTechnologies/GAE/humanmictweet/GAE/libraries/requests/api.py", line 40, in request
    return s.request(method=method, url=url, **kwargs)
  File "/Users/Rohan/Dropbox/MuktiTechnologiesINC/MuktiTechnologies/GAE/humanmictweet/GAE/libraries/requests/sessions.py", line 208, in request
    r.send(prefetch=prefetch)
  File "/Users/Rohan/Dropbox/MuktiTechnologiesINC/MuktiTechnologies/GAE/humanmictweet/GAE/libraries/requests/models.py", line 458, in send
    self.auth = get_netrc_auth(url)
  File "/Users/Rohan/Dropbox/MuktiTechnologiesINC/MuktiTechnologies/GAE/humanmictweet/GAE/libraries/requests/utils.py", line 43, in get_netrc_auth
    for loc in locations:
  File "/Users/Rohan/Dropbox/MuktiTechnologiesINC/MuktiTechnologies/GAE/humanmictweet/GAE/libraries/requests/utils.py", line 40, in <genexpr>
    locations = (os.path.expanduser('~/{0}'.format(f)) for f in NETRC_FILES)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 260, in expanduser
    userhome = pwd.getpwuid(os.getuid()).pw_dir
AttributeError: 'module' object has no attribute 'getuid'
4

3 に答える 3

14

前述のように、スタンドアロンの urllib3 の master ブランチは現在 AppEngine をサポートしていると思われます (誰かがこの事実を確認したら、適切な PyPI リリースを行います) が、Requests はまだ AppEngine をサポートしていません。 AppEngine には存在しません。具体的には、発生したエラーは~/.netrc構成ファイルの読み込みに関係しています。

問題 #493を参照してください。

それだけの価値があるため、urllib3 で同等のものは次のようになります。

import urllib3
http = urllib3.PoolManager()
response = http.request('GET', 'someurl')

更新: AppEngine サポートを含むurllib3 v1.3が昨日リリースされました。

于 2012-03-18T23:20:11.227 に答える
9

Google Appengine (バージョン 1.9.18) では、リクエスト バージョン 2.3.0 (のみ!)は、ソケット サポートを有効にする課金を有効にしている場合、本番環境で動作します (ただし、SDK では動作しません)

Appengine SDK のリクエストは、すべての https:// リクエストで失敗します。

  ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

バージョン 2.4.1 の要求は次のエラーで失敗します。

  File "distlib/requests/adapters.py", line 407, in send
    raise ConnectionError(err, request=request)
  ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

バージョン 2.5.1 の要求は次のエラーで失敗します。

  File "distlib/requests/adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
  ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

ソケットのサポートに関する情報: https://cloud.google.com/appengine/docs/python/sockets/

PS: GAE でリクエストを使用する場合は、awsome を very painful に置き換えてください。

関連項目: Google App Engine で Python Requests ライブラリを使用できますか?

于 2015-02-16T15:03:13.143 に答える