小编rd1*_*108的帖子

在Google App Engine中使用Requests python库

我正在尝试在Google App Engine上使用令人敬畏的Requests库.我找到了urllib3的补丁,它请求依赖,与App Engine兼容.https://github.com/shazow/urllib3/issues/61

我能成功

import requests
Run Code Online (Sandbox Code Playgroud)

但是之后

response = requests.get('someurl')
Run Code Online (Sandbox Code Playgroud)

以下回溯失败.这是怎么回事?

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", …
Run Code Online (Sandbox Code Playgroud)

google-app-engine urllib3 python-requests

24
推荐指数
3
解决办法
1万
查看次数

是否可以使用boto从Google App Engine中的S3读取文件?

我想在Google App Engine的沙箱中操作存储在S3中的pickle python对象.我使用boto 文档中的建议:

from boto.s3.connection import S3Connection

from boto.s3.key import Key

conn = S3Connection(config.key, config.secret_key)
bucket = conn.get_bucket('bucketname')
key = bucket.get_key("picture.jpg")
fp = open ("picture.jpg", "w")
key.get_file (fp)
Run Code Online (Sandbox Code Playgroud)

但是这需要我写一个文件,这显然不是GAE沙盒中的犹太人.

我怎么能绕过这个?非常感谢您的帮助

python google-app-engine amazon-s3 boto amazon-web-services

7
推荐指数
1
解决办法
8510
查看次数

我可以打开与任意端口上运行的本地服务器的websocket连接吗?

我有一个本地服务器输出我的实时家庭传感器数据,我想在我的浏览器中可视化它.

我的问题是,我可以使用websocket打开从浏览器到本地服务器的连接吗?我该怎么做呢?

本地服务器运行在非http指定的端口号上,我无法更改.

sensor websocket

6
推荐指数
1
解决办法
3060
查看次数

抓一个网页,要求他们先给你一个会话cookie

我正试图从政府的"集合卷"数据库中抓取一个excel文件.但是,我必须访问此excel文件的URL:

http://nrega.ap.gov.in/Nregs/FrontServlet?requestType=HouseholdInf_engRH&hhid=192420317026010002&actionVal=musterrolls&type=Normal

要求我有一个来自政府网站的会话cookie附加到请求.

如何通过对登录页面的初始请求(当他们为您提供会话cookie时)获取会话cookie,然后使用它来点击上面的URL来获取我们的Excel文件?我在使用Python的Google App Engine上.

我试过这个:

import urllib2
import cookielib

url = 'http://nrega.ap.gov.in/Nregs/FrontServlet?requestType=HouseholdInf_engRH&hhid=192420317026010002&actionVal=musterrolls&type=Normal'


def grab_data_with_cookie(cookie_jar, url):
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
    data = opener.open(url)
    return data

cj = cookielib.CookieJar()

#grab the data 
data1 = grab_data_with_cookie(cj, url)
#the second time we do this, we get back the excel sheet.
data2 = grab_data_with_cookie(cj, url)

stuff2  = data2.read()
Run Code Online (Sandbox Code Playgroud)

我很确定这不是最好的方法.我怎么能更干净地,甚至使用请求库?

python google-app-engine urllib2 web-scraping

5
推荐指数
1
解决办法
1万
查看次数