0

Ok, obviously I am new at this. I got this Python traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 30
SyntaxError: invalid syntax

What does File "<string>" stand for?

My code contains an empty line @ line 30, so I'm assuming this doesn't refer to my code, but what DOES it refer to?

( I'm using Micropython on an ESP8266 )

This is my code:

import network
import tinyweb
import machine

# Connect to your WiFi AP
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('blabla', 'blabla')

# Create web server application
app = tinyweb.webserver()
count = 0

# Hello world index page (just to be sure - let's handle most popular index links)
@app.route('/')
@app.route('/index.html')
async def index(req, resp):
    await resp.start_html()
    await resp.send('<html><body><h1>Hello, world!</h1></html>\n')

# Counter REST API endpoint
@app.resource('/counter')
def counter(data):
    return {'name': 'Foo', 'counter': counter}

def pin_handler(p)
    global count
    count =count + 1

#pin=machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)  
#pin.irq(handler = pin_handler, trigger = Pin.IRQ_FALLING, hard = True)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)
Bigman74066
  • 369
  • 1
  • 12
  • Is this code in a file that you're executing, or are you running it in an interactive environment? – Chris Dec 22 '18 at 19:26
  • 1
    Possible Duplicate : [https://stackoverflow.com/questions/27193586/file-string-in-python-traceback](https://stackoverflow.com/questions/27193586/file-string-in-python-traceback) – Flob Dec 22 '18 at 19:28
  • @Chris: Its in a file – Bigman74066 Dec 22 '18 at 19:32
  • 1
    Possible duplicate of [File "" in python traceback](https://stackoverflow.com/questions/27193586/file-string-in-python-traceback) – Chris Dec 22 '18 at 19:35
  • you are missing colon on this line `def pin_handler(p)`. I know it's not the answer of your question, but it's the reason for the traceback you get. – buran Dec 22 '18 at 19:35
  • Damn... you are right. So the DOES just refer to my code... – Bigman74066 Dec 22 '18 at 19:36
  • check SO questions referred in previous comments that explain `File ""` – buran Dec 22 '18 at 19:40

1 Answers1

0

Thanks to buran I found the cause. The <string> apparently DOES just refer to my own code. I forgot to add a colon at the and of the pin_handler function and that somehow shifted the position the error occured downwards...

Bigman74066
  • 369
  • 1
  • 12