Question: I a trying to access a website's information programmatically, but on both Java and Python it is unable to resolve a hostname. If I specify the IP address, it changes the error to TLSV1_UNRECOGNIZED_NAME. This website is able to resolve without any additional work through any browser though. I have looked through a lot of potential solutions on here, but for Python it says this issue should have been resolved in 2.7 or 2.8, but I am using 3.10 and still getting that error. In Java, it claims that this is a known error, but the solutions presented such as removing the SNI header through a compilation option, or passing an empty hostname array to HTTPSURLConnection to cancel out the creation of the SNI header doesn't solve it. I have also tried setting the user agent to Mozilla as suggested by an answer on here, but that didn't change anything either. I am sure that it is something unusual about the website, but it is not one I own so I am unable to check much about its configuration. Specifically the website I am trying to see is: URL -> https://epic7db.com/heroes IP -> 157.230.84.20 DNS Lookup -> https://www.nslookup.io/domains/epic7db.com/webservers/  When using nslookup locally, I get back: nslookup epic7db.com Server: UnKnown Address: 10.0.0.1 Non-authoritative answer: Name: epic7db.com Address: 157.230.84.20  Any help would be appreciated as I am essentially throwing things at the wall to see what sticks at this point. EDIT: Adding code samples Python: import requests headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'} # This is chrome, you can set whatever browser you like url = 'https://epic7db.com' a = requests.get(url,headers) print(a.content)  Kotlin using Java's HttpsUrlConnection: import http.SSLSocketFactoryWrapper import java.net.URL import javax.net.ssl.* fun main() { HttpsURLConnection.setDefaultHostnameVerifier { hostName, session -> true } val url = URL("https://epic7db.com") val sslParameters = SSLParameters() val sniHostNames: MutableList<SNIHostName> = ArrayList<SNIHostName>(1) // sniHostNames.add(SNIHostName(url.getHost())) sslParameters.setServerNames(sniHostNames as List<SNIServerName>?) val wrappedSSLSocketFactory: SSLSocketFactory = SSLSocketFactoryWrapper(SSLContext.getDefault().socketFactory, sslParameters) HttpsURLConnection.setDefaultSSLSocketFactory(wrappedSSLSocketFactory) val conn = url.openConnection() as HttpsURLConnection conn.hostnameVerifier = HostnameVerifier { s: String?, sslSession: SSLSession? -> true } println(String(conn.inputStream.readAllBytes())) }  Suggested helper class in Kotlin/Java: package http; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class SSLSocketFactoryWrapper extends SSLSocketFactory { private final SSLSocketFactory wrappedFactory; private final SSLParameters sslParameters; public SSLSocketFactoryWrapper(SSLSocketFactory factory, SSLParameters sslParameters) { this.wrappedFactory = factory; this.sslParameters = sslParameters; } @Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { SSLSocket socket = (SSLSocket) wrappedFactory.createSocket(host, port); setParameters(socket); return socket; } @Override public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException { SSLSocket socket = (SSLSocket) wrappedFactory.createSocket(host, port, localHost, localPort); setParameters(socket); return socket; } @Override public Socket createSocket(InetAddress host, int port) throws IOException { SSLSocket socket = (SSLSocket) wrappedFactory.createSocket(host, port); setParameters(socket); return socket; } @Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { SSLSocket socket = (SSLSocket) wrappedFactory.createSocket(address, port, localAddress, localPort); setParameters(socket); return socket; } @Override public Socket createSocket() throws IOException { SSLSocket socket = (SSLSocket) wrappedFactory.createSocket(); setParameters(socket); return socket; } @Override public String[] getDefaultCipherSuites() { return wrappedFactory.getDefaultCipherSuites(); } @Override public String[] getSupportedCipherSuites() { return wrappedFactory.getSupportedCipherSuites(); } @Override public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { SSLSocket socket = (SSLSocket) wrappedFactory.createSocket(s, host, port, autoClose); setParameters(socket); return socket; } private void setParameters(SSLSocket socket) { socket.setSSLParameters(sslParameters); } } 

Answer:  How can I get around an unresolved hostname or unrecognized name error using HTTP(S) in java or python?  This is most likely not a problem in the Java or Python code1. A failure to resolve a DNS name is most likely caused by:  not talking to the correct DNS server(s), or a failure in the authoritative server, or a change in the authoritative server that hasn't propagated yet.  (And 3. will more likely manifest as the DNS name resolving to the wrong IP address, not a resolution failure. Read about DNS entry TTLs.) So ... you don't get around it >in the program<. You get around it by looking outside the program to figure out why the DNS resolution is failing. Then you make changes to fix that. A couple of reasons why a browser might work but a Java or Python application might not (or vice versa):  The browser may be configured to send all HTTP / HTTPS requests through a proxy. The proxy may have different DNS access to the machine you are running your code on.  In the case of Java (at least on Linux), Java has its own way of configuring the "local" DNS server. Normally that is not a problem, but sometimes it could mean that your application and browser are using different servers.    When you tried to use the IP address in the URL, you bypassed the DNS lookup step. But then you ran into the problem that TLS certificates will not work with IP addresses. (You could "hack" around this, but the hacks have potentially serious security implications.)  1 - As others have pointed out, there is nothing wrong with the code you added to the question. Indeed, Thorbjørn attests that the code works for him exactly as written!