httplib.InvalidURL: nonnumeric port:

This might be a simple solution, here

connection = httplib.HTTPConnection(url)

you are using the httpconnection so no need to give url like, http://OSMQuote.com but instead of that you need to give OSMQuote.com.

In short remove the http:// and https:// from your URL, because the httplib is considering : as a port number and the port number must be numeric,

Hope this helps!


nonnumeric port:

Solution :

http.client.HTTPSConnection("api.cognitive.microsofttranslator.com")

Remove "https://" from Service URL or Endpoint and it will work.

https://appdotpy.wordpress.com/2020/07/04/errorsolved-nonnumeric-port/


httplib.HttpConnection takes the host and port of the remote URL in its constructor, and not the whole URL.

For your use case, it's easier to use urllib2.urlopen.

import urllib2

with open('urls.txt') as urls:
    for url in urls:
        try:
            r = urllib2.urlopen(url)
        except urllib2.URLError as e:
            r = e
        if r.code in (200, 401):
            print '[{}]: '.format(url), "Up!"
        elif r.code == 404:
            print '[{}]: '.format(url), "Not Found!" 

Tags:

Python

File