How do you run , in Windows , this python script meant for Linux?
Question: I am using Python 3.5 on a Windows 7 computer.

I am trying to run a python script designed to run in Linux found in this book
Learning Python Network Programming by Dr. M. O. Faruque Sarker and Sam
Washington Jun 17, 2015 Chapter 6. IP and DNS GeoIP look-ups

..........The code is saved in my C drive as C:\Python35\geoiplookup.py I had
renamed it from "6_3_geoip_lookup.py" to "geoiplookup.py" ..........Here is
the code and also shown in a more user friendly image at
<http://imgur.com/PM196AV> ..........

    
    
    import socket
    from geoip import geolite2
    import argparse
    
    
    if __name__ == '__main__':
        # Setup commandline arguments
        parser = argparse.ArgumentParser(description='Get IP Geolocation info')
        parser.add_argument('--hostname', action="store", dest="hostname", required=True)
    
        # Parse arguments
        given_args = parser.parse_args()
        hostname =  given_args.hostname
        ip_address = socket.gethostbyname(hostname)
        print("IP address: {0}".format(ip_address))
    
        match = geolite2.lookup(ip_address)
        if match is not None:
            print('Country: ',match.country)
            print('Continent: ',match.continent) 
            print('Time zone: ', match.timezone) 
    

..........This script will show an output similar to the following (in Linux):

    
    
    $ python 6_3_geoip_lookup.py --hostname=amazon.co.uk
    IP address: 178.236.6.251
    Country:  IE
    Continent:  EU
    Time zone:  Europe/Dublin
    

..........I tried running the .py file in Python GUI shell in Windows using
the following commands without success. Please see picture at
<http://imgur.com/wZ4m1S5> ..........

    
    
    import geoiplookup
    --hostname=amazon.co.uk
        SyntaxError: can't assign to operator
    
    --hostname='amazon.co.uk'
        SyntaxError: can't assign to operator
    
    '--hostname'='amazon.co.uk'
        SyntaxError: can't assign to literal
    
    '--hostname'=amazon.co.uk
        SyntaxError: can't assign to literal
    

Before you accused me of not trying this in the command line:

    
    
    C:\Python35>python geoiplookup.py --hostname=amazon.co.uk
    

I have, and I got an error message:

    
    
    IP address: 178.236.6.251
    Traceback (most recent call last):
    File "geoiplookup.py", line 17, in <module> match = geolite2.lookup(ip_address)
    File "c:\Python35\lib\site-packages\geoip.py", line 382, in _read_mmdb_metadata
    TypeError: a bytes-like object is required, not 'str'
    c:\Python35>
    

Please advise . Thanks a million.

Thank you very much.


Answer: You aren't running the Python script, you're in the Python interpreter and
attempting to run each line of code.

Look at your Linux output:

    
    
    $ python 6_3_geoip_lookup.py --hostname=amazon.co.uk
    IP address: 178.236.6.251
    Country:  IE
    Continent:  EU
    Time zone:  Europe/Dublin
    

That first line is important. _That_ is what you should be running on your
Windows command line:

    
    
    C:\Python35>python geoiplookup.py --hostname=amazon.co.uk
    

