2012-03-18 29 views
23

Tôi đang cố gắng sử dụng thư viện Yêu cầu tuyệt vời trên Google App Engine. Tôi tìm thấy một bản vá cho urllib3, mà yêu cầu dựa vào, tương thích với App Engine. https://github.com/shazow/urllib3/issues/61Sử dụng thư viện python Yêu cầu trong Google App Engine

tôi có thể thành công

import requests 

nhưng sau đó

response = requests.get('someurl') 

không thành công với traceback sau. Chuyện gì vậy?

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' 
+0

bản sao có thể có của [Yêu cầu: HTTP cho con người - python-requests.org trên Google App Engine] (http://stackoverflow.com/questions/9604799/requests-http-for-humans-python-requests- org-on-google-app-engine) –

Trả lời

13

Như đã đề cập, master branch of standalone urllib3 được cho là hỗ trợ AppEngine bây giờ (tôi sẽ làm một PyPI phát hành đúng một lần một ai đó khẳng định sự thật này), nhưng yêu cầu chưa hỗ trợ AppEngine vì nó làm cho giả thiết về hệ thống tập tin thứ khác nhau để tải các tập tin cấu hình không tồn tại trên AppEngine. Cụ thể là lỗi bạn gặp phải có liên quan đến việc tải tệp cấu hình ~/.netrc.

Xem Issue #493.

Đối với những gì nó có giá trị, tương đương với trong urllib3 sẽ là:

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

Cập nhật:urllib3 v1.3 được phát hành ngày hôm qua bao gồm hỗ trợ AppEngine.

+0

cảm ơn nhiều, shazow. Tôi đang sử dụng urllib3 được vá của bạn trên App Engine thành công. Đoán chúng ta sẽ phải xem làm thế nào khó khăn trừu tượng đi một số công cụ hệ thống tập tin cấp thấp này là. – rd108

9

Trên Google AppEngine (phiên bản 1.9.18) requestsphiên bản 2.3.0 (chỉ!) làm việc TRONG SẢN XUẤT (nhưng không phải trên SDK) nếu bạn có bật thanh toán, cho phép hỗ trợ socket.

yêu cầu trên AppEngine SDK không thành công với tất cả các địa chỉ https: // yêu cầu:

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

yêu cầu phiên bản 2.4.1 không thành công với:

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

yêu cầu phiên bản 2.5.1 không thành công với:

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

Thông tin về hỗ trợ ổ cắm: https://cloud.google.com/appengine/docs/python/sockets/

PS: Thay thế awsome với rất đau đớn nếu bạn định sử dụng yêu cầu trên GAE.

Xem thêm: Can Python Requests library be used on Google App Engine?

+0

Nhưng có thể sử dụng [urlfetch] (https://cloud.google.com/appengine/docs/python/urlfetch/). Tự hỏi nếu nó có thể làm cho 'yêu cầu' sử dụng nó. – wlnirvana

+0

No. Người duy trì yêu cầu không hỗ trợ appengine. Trong hầu hết các trường hợp, bạn có thể thay thế/monkeypatch các cuộc gọi từ libs của bên thứ 3 đến các yêu cầu với urlfetch khá dễ dàng hoặc yêu cầu monkeypatch trực tiếp với các cuộc gọi tương thích tới urlfetch. Chúng tôi đã có một mô-đun được gọi là yêu cầu giả mạo giả mạo. – cat

+0

phiên bản 2.3.0 thực sự đã làm điều đó cho tôi. Xem http://stackoverflow.com/questions/29301863/google-app-engine-and-human-api-python-lib –

Các vấn đề liên quan