简体   繁体   English

如何在Python请求中禁用SNI?

[英]How to disable SNI in Python Requests?

I'm attempting to use requests to access a remote server over SSL. 我正在尝试使用requests通过SSL访问远程服务器。 Unfortunately it's misconfigured such that it responds with the error TLSV1_UNRECOGNIZED_NAME during the SNI handshake, which is ignored by browsers but raises an exception in requests . 不幸的是,它的配置错误,因此在SNI握手期间会以错误TLSV1_UNRECOGNIZED_NAME进行响应,浏览器会忽略该错误,但会在requests引发异常。

This appears to be the same issue as this question, but in Python rather than Java: SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0 ` 这似乎是与该问题相同的问题,但是在Python中而不是Java中: SSL握手警报:自升级到Java 1.7.0后出现unrecognized_name错误。

The connection works perfectly in Python 2, which doesn't support SNI. 该连接可在不支持SNI的Python 2中完美运行。 How can I disable SNI in Python 3 so that the connection works? 如何在Python 3中禁用SNI,以便连接正常?

I couldn't find a way to disable SNI on the requests level, but I found a hack that will trick it into thinking SNI isn't supported. 我找不到在requests级别禁用SNI的方法,但是我发现了一个黑客,可以诱使它认为不支持SNI。 Add this code before importing requests (not after, or it will be too late): 在导入requests之前添加以下代码(不要在之后添加,否则为时已​​晚):

import ssl
ssl.HAS_SNI = False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM