Search code examples
pythonwebrequestpython-idle

IDLE throwing error for no reason


Ok so im absolutely stumped with some super basic python coding. I feel like an ass for having to ask this but here goes. im attempting to build a basic port scanner. im using code that i have absolutely used before and has worked. yet my IDLE is throwing up errors each time my code is run.

my code snippet

##Request ip address and first port
web_request=urllib2.urlopen("http://" + ip + ":" + list(islice(port, 1))

##Define variable site as reading the webpage/ip address data
server=web_request.read()

##Show not open if length of site data is less than or equal to 1
if len(server)<='1':
    print ip + ":" + list(islice(port, 1)) + " Not open"

etc. etc. etc.

when it gets to "server=web_request.read()" IDLE gives me an invalid syntax error saying "server" is the issue. Ive tried changing server to other keywords (eg. IP, WEBSITE, SITE) to no avail. any idea why idle wont accept my code?


Solution

  • Your web_request has three open parentheses and only two closing ones.

    # open:                    1                           2      3
    web_request=urllib2.urlopen("http://" + ip + ":" + list(islice(port, 1))
    # close:                                                              12
    

    That's almost certainly what's causing the issue in that it considers the server line to be a continuation.