Getting Pico W onto WiFi

I bought a Raspberry Pico W before Christmas and started to play around with it. Got it to connect with Thonny and started talking to it, but when I try to connect it to WiFi I keep getting a syntax warning I don’t understand and can’t fix. It all looks OK to me but it won’t run. I’ve added Xs where the SSID and Password were for privacy reasons.

import network
import socket
from time import sleep
from picozero import pico_temp_sensor, pico_led
import machine

ssid = xxxxxxxx
password = xxxxxxxxxxxx

def connect():
#Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan(xxxxxxxx, xxxxxxxxxxxxx

Traceback (most recent call last):
File “”, line 8
SyntaxError: invalid syntax

I apologize if I’ve broken any rules as this is my first post and I’m not a coder, obviously. I don’t have any Python knowledge so I came here in the hope someone will know what was wrong.

Thanks a lot.


Please wrap code in triple backticks to preserve the formatting:

if True:
    print(''Hello world!')

Which is line 8?

Possibly it’s the missing closing parenthesis of:

wlan(xxxxxxxx, xxxxxxxxxxxxx

I’m assuming that the the all xxxxx are just private bits that you’re hiding for security reasons.

Looks to me like you are missing quotes around your ssid and password.

Hi Guy’s
Yep, I knew I’d cock it up somewhere on this forum, better now than later on. What are backticks?

1 import network
2 import socket
3 from time import sleep
4 from picozero import pico_temp_sensor, pico_led
5 import machine

7 ssid = xxxxxxxx
8 password = xxxxxxxxxxxx

But if you start putting quotes around the password won’t that mess up the password by adding ) or : onto the end?


A backtick is `, Unicode U+0060, as I posted in the example. I put 3 of them in a line before and a line after the code to preserve the formatting.

Here’s some plain text:

if True:
print(“Hello world!”)

Then the exact same text with 3 backticks ``` on the lines before and after:

if True:
    print("Hello world!")

If you’re including the ssid and password in the program, it would look like:

ssid = "my_ssid"
password = "my_password"

Thank you, Mathew, for explaining the backtick.

All this started because I bought a book called “The Latest raspberry Pi Pico W Guide 2022” and tried one of the scripts “Connect your raspberry pi pico W to a wifi network” Well if that script was wrong that means every copy of that book has the wrong script in it.

Could you suggest a decent MicroPython book I could get started with?

Thanks again for your help.


On most American keyboards, the `/~ key should be to the left of the 1/! key.

It is possible that the book author intended that xxxxxxxxxx should include needed quotes. But omission of a closing ) is definitely a typo. Mistakes in printed code (and math equations) is an unfortunate reality and especially bad when one does not know the language. Consider doing at least a chapter or two of the Python Tutorial. The Python Tutorial — Python 3.11.1 documentation