0

I am making a custom settings file for a webserver, and the settings file looks like this:

[server]
adress = "127.0.0.1"
port = 8080

The code to parse this:

def main():
    parser = SafeConfigParser()
    parser.read("settings.cfg")
    global adress, port
    adress = parser.get("server", "adress")
    port = int(float(parser.get("server", "port").rstrip()))
    print(adress + str(port))

Printing the code at the end give the string: "127.0.0.1"8080. Somehow though my http.server server does not accept those as inputs: httpd = server_class((adress, port), Handler) gives the following error:

    httpd = self.server_class((adress, port), Handler)
  File "C:\Python33\lib\socketserver.py", line 430, in __init__
    self.server_bind()
  File "C:\Python33\lib\http\server.py", line 135, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Python33\lib\socketserver.py", line 441, in server_bind
    self.socket.bind(self.server_address)
socket.gaierror: [Errno 11004] getaddrinfo failed

When I just type ("127.0.0.1", 8080) for the input, it does work, but it's exactly the same as what comes out of the config file. I also tried localhost and 192.168.1.3 in the config file, and that does not work either. How would I fix this? Other answers have said it's a problem with a newline, but printing adress + port does not display a newline on either of those

IPDGino
  • 706
  • 1
  • 8
  • 17

1 Answers1

0

Fixed it myself!

I think SafeConfigParser reads a settings file as a string in whole, even if you put integers in the config file. All I did was change the line adress = "127.0.0.1" to adress = 127.0.0.1 and it works now. I would still like an explanation from someone, as I do not fully understand why this is the case.

IPDGino
  • 706
  • 1
  • 8
  • 17