2

There is a web service where I upload files one by one and it proccess them somehow and returns me a result. There is a weird thing about it, however. If a file is big, it causes an error. If it's not so big, then everything is ok.

My guess to solve this problem is try to upload small chuncks of a file until it's uploaded completely instead of uploading a whole file.

The service uses https connection.

How do I do that in Python: how do I read a file and send read peaces to a server? And how do I read a result: peace sent - read a result or peaces sent - read a whole result?

Mataba
  • 97
  • 1
  • 10

1 Answers1

1

I'm not sure if this is what you're looking for -- chunk encoded requests using the Requests library: http://www.python-requests.org/en/latest/user/advanced/#chunk-encoded-requests

Supply a generator that sends chunks of your file:

def gen():
    yield 'hi'
    yield 'there'

requests.post('http://some.url/chunked', data=gen())
zallarak
  • 5,287
  • 7
  • 38
  • 54
  • @MariusKavansky Just handle it like you'd handle a streaming request. I don't know what you're running on your server. – zallarak Aug 12 '13 at 04:31
  • Yeah here is one: http://stackoverflow.com/questions/12871362/streaming-data-of-unknown-size-from-client-to-server-over-http-in-python, @Mataba – zallarak Aug 12 '13 at 04:45