【发布时间】:2018-06-27 14:03:33
【问题描述】:
尝试使用 Flask 从 Pythonanywhere(付费帐户)上的 Web 应用发出请求。这在本地 PC 上根据需要工作,但在 Pythonanywhere 上收到错误。
@app.route('/test/')
def test():
url_cookies='https://www.phoenixcontact.com/online/portal/ru/pxc/offcontext/'
headers = {'authority': 'www.phoenixcontact.com', 'method': 'GET','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
requestCookies = requests.get(url_cookies,headers=headers)
return 'Test'+requestCookies.text
【问题讨论】:
-
您遇到的错误是什么?您对
requests.get的调用将返回一个response对象。您将其称为requestCookies,因此了解requestCookies.status_code和requestCookies.content的值会很有用。 -
我收到 504 错误,我试图请求的站点似乎只是阻止了来自 pythonanywhere 的任何活动。
标签: pythonanywhere