简体   繁体   中英

SyntaxError: EOL while scanning string literal

I am getting a Syntax Error EOL on the print line. I tried adding more commas but it wont work.

def getAuthorized(url, username, password):

r = requests.get(url, auth=(username, password))

    if str(r.status_code) != '401':
        print "\n[!] Username: " + username + " Password: " + password + " 
         Code: " + str(r.status_code) +  "\n"

Thank you in advance!!

Adding commas will not work. The Problem Here is that:

def getAuthorized(url, username, password):

r = requests.get(url, auth=(username, password))

    if str(r.status_code) != '401':
        print "\n[!] Username: " + username + " Password: " + password + " 
         Code: " + str(r.status_code) +  "\n"

You can split the print into two lines, but I don't suggest you to. The print line should be:

print "\n[!] Username: " + username + " Password: " + password + " Code: " + str(r.status_code) +  "\n"

So the final code should be:

def getAuthorized(url, username, password):

r = requests.get(url, auth=(username, password))

    if str(r.status_code) != '401':
        print "\n[!] Username: " + username + " Password: " + password + " Code: " + str(r.status_code) +  "\n"

The problem is in "…Code: " — Python doesn't allow to make a single-quoted string multiline; only triple-quoted strings can be multiline. To fix:

print "\n[!] Username: " + username + " Password: " + password + \
      " \n Code: " + str(r.status_code) +  "\n"

Please note a backslash at the end of the first line: it's required to continue the statement print on the next line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM