Ticket #7427: twisted_reproduce.py

File twisted_reproduce.py, 661 bytes (added by immerrr, 6 years ago)

minimal example to reproduce the defect

Line 
1from cStringIO import StringIO
2import time
3
4from twisted.internet import reactor, task
5from twisted.web import server, resource, client, http_headers
6
7
8def main(argv):
9    site = server.Site(resource.Resource())
10    port = reactor.listenTCP(27500, site)
11
12    agent = client.Agent(reactor)
13    bodyProducer = client.FileBodyProducer(StringIO('[1,2,3]'))
14    req = agent.request(
15        'POST', 'http://127.0.0.1:27500/',
16        http_headers.Headers({'Content-Type': ['application/json']}),
17        bodyProducer)
18
19    reactor.callLater(0.05, req.cancel)
20    reactor.callLater(0, time.sleep, 0.1)
21
22    return req
23
24if __name__ == '__main__':
25    task.react(main)