扭曲的.web导入时找不到

2024-10-03 23:27:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在UbuntuServer13.0和Python2.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()

当我试图运行它时,它给出了以下错误:

^{pr2}$

我在python控制台中尝试过扭曲的互联网有用,但不行扭曲的.web. 有人对如何处理这种问题有什么建议吗?在

谢谢


Tags: fromimportselfwebmainresponsedeftwisted