简体   繁体   English

如何在Python中覆盖请求的随机生成的多部分边界?

[英]How can I override requests' randomly generated multipart boundary in Python?

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. 这会产生每次具有不同多部分边界的请求。 ie, 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. 出于测试目的,我想修复一些值,如I_AM_NOT_A_MULTIPART_BOUNDARY或其他一些值。

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python请求的多部分数据POST:未找到多部分边界 - multipart data POST using python requests: no multipart boundary was found "如何使用 python 请求设置内容类型的边界?" - How can I set boundary of Content-type using python requests? Python请求保存随机生成的图像 - Python requests save randomly generated image 如何在Geodjango的城市边界内创建随机生成的用户个人资料? - How to create a randomly generated user profile within a city boundary in Geodjango? 如何使随机生成的字符串成为 python 中的 class 的实例? - How do I make a randomly generated string an instance of a class in python? 如何找到随机生成的位置旁边的位置 - how can i find the location next to a randomly generated location 在 python attrs class 中,如何用我自己的方法覆盖生成的 __init__ - in a python attrs class, how can I override generated __init__ with my own 如何将短语打印为随机生成的数字? - How can I print the phrase as the randomly generated numbers? 如何从随机生成的列表中进行选择? - How can I choose from list that generated randomly;? 如何覆盖 ScraPy 的请求并改用 python-requests? - How can I override ScraPy's Request and use python-requests instead?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM