Вопрос

Example:

with open('foobar.txt') as f:
    r = requests.post("http://requestb.in/179gbs61", files={'file':f})

This produces a request with a different a multipart boundary every time. i.e., this call produces a different request every time.

For the purposes of testing, I would like to fix to some value like I_AM_NOT_A_MULTIPART_BOUNDARY or some such.

Q: How can I go about this?

Это было полезно?

Решение

Try this:

import requests.packages.urllib3 as urllib3
urllib3.filepost.choose_boundary = lambda: 'I_AM_NOT_A_MULTIPART_BOUNDARY'

with open('foobar.txt') as f:
    r = requests.post("http://requestb.in/179gbs61", files={'file':f})
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top