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)
7
  • Is this code in a file that you're executing, or are you running it in an interactive environment? Commented Dec 22, 2018 at 19:26
  • 1
    Possible Duplicate : https://stackoverflow.com/questions/27193586/file-string-in-python-traceback Commented Dec 22, 2018 at 19:28
  • @Chris: Its in a file Commented Dec 22, 2018 at 19:32
  • 1
    Possible duplicate of File "<string>" in python traceback Commented Dec 22, 2018 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. Commented Dec 22, 2018 at 19:35

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.