我试图在 Ubuntu 服务器 13.0 和 python 2.7 中运行以下 python 代码
from twisted.python.log import err
from twisted.web.client import Agent
from twisted.internet import reactor
from twisted.internet.ssl import ClientContextFactory
from twisted.web.http_headers import Headers
from stringproducer import StringProducer
class WebClientContextFactory(ClientContextFactory):
def getContext(self, hostname, port):
return ClientContextFactory.getContext(self)
def display(response):
print "Received response"
print response
def main():
contextFactory = WebClientContextFactory()
agent = Agent(reactor, contextFactory)
d = agent.request("POST", "https://myweburl");
d.addCallbacks(display, err)
d.addCallback(lambda ignored: reactor.stop())
reactor.run()
if __name__ == "__main__":
main()
当我尝试运行它时,它给了我以下错误:
ImportError: No module named twisted.web.client
我曾在 python 控制台中尝试过它,并且 twisted.internet 可以工作,但无法使用 twisted.web。有人对如何处理此类问题有任何建议吗?
谢谢