issue passing URL from json config file to python script
Question: I'm currently writing a small python script to monitor all Urls within my
teams pool of web apps. I have a python script that basically runs in an
infinite loop and will check the urls every 60 min. My issue lies in pulling
my url's from my json config. for some reason I cannot use a url that has the
adress:port and extension thereafter

My python script or function is as follows(partial) and basically bombs out
when it gets to the connection portion conn = httplib.HTTPConnection(website).
The issue lies in reading URLs in this format ("url":
"zardev0201230265:7778/apt/server/login/#")

    
    
    def monitor():
      import httplib
      import logging
      import json
      import os
      p = os.getpid()
    
    #Basic config for / displays what will appear in log file
    #Open Json config file and use data function to load and read the file
      logging.basicConfig(filename='SalesTriggerCHECK.log', format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)
      with open('htppchecklogconfig.json') as json_data_file:
       data = json.load(json_data_file)
    
    #Declare i as counter to iterate through json list, range will be set to length of the list
    #Assign data for current iteration for server/category and URL to variables
      for i in range(len(data["application_details"])):
       server = (data["application_details"][i]["server"])
       application = (data["application_details"][i]["application"])
       category = (data["application_details"][i]["category"])
       website = (data["application_details"][i]["url"])
    
    #Connection settings that are required to make a connection request to check URL
    #The data function is used in conjunction with the counter(i) to find the URL in the Json file
    #Res variable stores response from connection request / if statement checks for status 200 for ok
    #We can get the response code and reason using the the get response function when make the connection
       conn = httplib.HTTPConnection(website)
       conn.request("HEAD", "/index.html")
       res = conn.getresponse()
    

My JSON config file is as follows:

    
    
    {
        "application_details": [
              {
                "server": "Server120",
                "application": "sales application",
                "category": "DEV",
                "url": "zardev0201230265:7778/apt/server/login/#"
            },
            {
                "server": "Server130",
                "application": "Dashboard-Hangfire",
                "category": "DEV",
                "url": "zardev0201230297:7779"
            }
    
    
        ]
    

error details

    
    
    Traceback (most recent call last):
      File "C:\Users\pc\Desktop\app\httpchecklog.py", line 50, in <module>
        monitor()
      File "C:\Users\pc\Desktop\app\httpchecklog.py", line 33, in monitor
        conn = httplib.HTTPConnection(website)
      File "C:\Python27\lib\httplib.py", line 751, in __init__
        (self.host, self.port) = self._get_hostport(host, port)
      File "C:\Python27\lib\httplib.py", line 792, in _get_hostport
        raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
    InvalidURL: nonnumeric port: '7778/apt/server/login/#'
    

any advice around this would be highly appreciated


Answer: As it says in the exception: nonnumeric port. The HTTPConnection class
interprets everything after the ':' as the port, in your case:
'7778/apt/server/login/#'. This can only be numeric. If you change it to
'7778', the exception shouldn't occur.

The available parameters can be found in the python docs:
<https://docs.python.org/2/library/httplib.html>

