我试图在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。任何人都有任何建议如何处理这样的问题?
由于
答案 0 :(得分:4)
你是否安装了扭曲的网页?您必须在Ubuntu下安装python-twisted-web
软件包:
sudo apt-get install python-twisted-web