如何在Python请求中指定源IP地址
我在网络接口卡上配置了几个IP地址。我需要指定通过哪个IP地址python 请求
必须连接到Web服务器。是否可以?
import requests
r = requests.get("http://example.com/foo/bar")
我需要强制requests.get
通过划定的IP地址执行HTTP请求。
还有其他http库
在Python中支持此功能吗?
I have several IP addresses configured on my network interface card. I need to specify through which IP address python requests
must connect to the web server. Is it possible?
import requests
r = requests.get("http://example.com/foo/bar")
I need to force requests.get
to perform http request through a dasignated IP address.
Is there any other http library
that support this feature in python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 sourceaddressadapter 来自Respections-toolbelt:sourceaddressadapter
You can use a SourceAddressAdapter from requests-toolbelt:
您是否正在运行Django/Django-Rest项目?因为,如果是这样,您只需在
python manage.py runserver
命令中指定自定义主机和端口!喜欢:希望我理解问题
Are you running a Django/Django-Rest project? Because, if so, you can just specify a custom host and port into the
python manage.py runserver
command! Like so:Hope I understood the problem