我在Linux機器上使用安裝了web.py(v0.38)的Python 2.7.5。下面是我在最基本的形式代碼(webhooks.py)如何在Python 2.7 web.py上啓用HTTPS?
#!/usr/bin/python
import web
urls = ('/.*','WebHooks')
app = web.application(urls, globals())
class WebHooks:
def POST(self):
raw_payload = web.data()
json_encode = json.loads(raw_payload)
if __name__ == '__main__':
app.run()
- 我執行
python webhooks.py 9999
- 它開闢了一個本地端口
http://0.0.0.0:9999/
我的問題:我已閱讀文檔位於,我很難過。有人能幫我打開一個HTTPS網址嗎? https://0.0.0.0:9999/
我已經試過
添加以下到我的代碼進行測試:
response = app.request("/.*", https=True)
我會得到一個錯誤:AttributeError: 'module' object has no attribute 'request'
我解決了這個問題與pip install urllib.py
然後將import urllib
添加到我的代碼的頂部,但我結束了一堆錯誤:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/web/application.py", line 239, in process
return self.handle()
File "/usr/lib/python2.7/site-packages/web/application.py", line 230, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/lib/python2.7/site-packages/web/application.py", line 461, in _delegate
cls = fvars[f]
KeyError: u'WebHooks'
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/web/application.py", line 239, in process
return self.handle()
File "/usr/lib/python2.7/site-packages/web/application.py", line 229, in handle
fn, args = self._match(self.mapping, web.ctx.path)
AttributeError: 'ThreadedDict' object has no attribute 'path'
謝謝!我會在明天早上嘗試第一件事並更新這個狀態。 –
更新:您的解決方案工作正常!對於也在嘗試這種方式的其他讀者,我必須確保在工作之前有兩件事。首先,您需要在您的系統上安裝openssl-devel,然後使用pip安裝pyOpenSSL。 –