e-info128
e-info128

Reputation: 4072

How to request https by ip address?

How to make a https request by ip address?, by example, with cloudflare:

>>> import requests
>>> requests.get('https://104.18.5.125/', verify=False, headers={ 'host': 'example.com' })
...
requests.exceptions.SSLError: HTTPSConnectionPool(host='104.18.5.125', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')])")))

But when make the request using the original hostname works fine.

>>> requests.get('https://example.com/', verify=False)
<Response [200]>

When try access from Mozilla Firefox says: SSL_ERROR_NO_CYPHER_OVERLAP.

Need test remote https servers for virtual host checking, but can not made the request using the ip address. How to disable warnings from python3 code and made the request?

Upvotes: 1

Views: 1443

Answers (2)

David K. Hess
David K. Hess

Reputation: 17246

There is now a requests adapter available which makes this possible:

https://toolbelt.readthedocs.io/en/latest/adapters.html#hostheaderssladapter

In use, it looks like:

import requests
from requests_toolbelt.adapters import host_header_ssl
s = requests.Session()
s.mount('https://', host_header_ssl.HostHeaderSSLAdapter())
s.get("https://93.184.216.34", headers={"Host": "example.org"})

Upvotes: 0

kinshukdua
kinshukdua

Reputation: 1994

SSL certificates usually include the domain name for the website but not the IP, this means when you tried making a request using HTTPS, since there was no available certificate for the IP it resulted in an handshake failure.

To fix this you need to either stop using HTTPS or get an SSL certificate for the IP address.

Upvotes: 1

Related Questions