我正在学习扭曲尝试构建RSS聚合器。当我尝试建立使用Web代理请求,有人告诉我,我没有提供URL参数为字节:扭曲的代理将不会建立字节的请求
[Failure instance: Traceback (failure with no frames): <class 'twisted.web._newclient.RequestGenerationFailed'>: [<twisted.python.failure.Failure builtins.TypeError: sequence item 0: expected a bytes-like object, str found>]
但我认为我所做的:
from twisted.internet import reactor
from twisted.web.client import Agent
def request_sent(response):
print ('I got something!')
def request_failed(reason):
print (reason)
def feed_loader_main():
"""
Starts and manage the reactor
"""
agent = Agent(reactor)
d = agent.request(
'GET',
'http://www.example.com'.encode('utf8') ##### <- HERE
)
d.addCallback(request_sent)
d.addErrback(request_failed)
print ('Firing reactor!')
reactor.run()
if __name__ == '__main__':
feed_loader_main()
它是扭曲的黑色魔术在这里发生还是仅仅是糟糕的编码?
你可以编辑你的问题,包括Twisted和Python版本号吗? 'Agent'和Python 3有一个问题,但我相信它刚刚解决了。尽管如此,尝试用'b'加前缀字符串(如果你使用Python 3) – yorodm