Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error
#1
Hi. Im studing. I need to help. I will connect mysql from python in vscode. Im write cmd pip install mysql-connector. And im write vscode terminal pip install mysql-connector. And im write :

import mysql.connector


mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd=""
)

mycursor = mydb.cursor()

mycursor.execute("show database")

for x in mycursor:
    print(x) 
But i see error : import mysql.connector
^
SyntaxError: invalid character in identifier
Reply
#2
did you install it?
python -m pip install mysql-connector
Reply
#3
You should use BBcode to post an error message. Perhaps we would then be able to see at which postion the caret (^) points. But "invalid caracter" means most of the time an invisible character, only to be found with a hex-editor or so. Best is to remove the entire line and then type it again.
What editor or IDE are you using? Some of them automatically insert a BOM (Byte Order Mark) at the beginning of a text file.
Reply
#4
(Mar-06-2020, 10:27 AM)Larz60+ Wrote: did you install it?
python -m pip install mysql-connector

Yes. terminal write and extra cmd write.
Sorry my english bad im Turkish...

(Mar-06-2020, 10:48 AM)ibreeden Wrote: You should use BBcode to post an error message. Perhaps we would then be able to see at which postion the caret (^) points. But "invalid caracter" means most of the time an invisible character, only to be found with a hex-editor or so. Best is to remove the entire line and then type it again.
What editor or IDE are you using? Some of them automatically insert a BOM (Byte Order Mark) at the beginning of a text file.
Visual Studio Code
Reply
#5
Ibreeden şunu yazdı:

Quote:Bir hata mesajı göndermek için BBcode kullanmalısınız. Belki de, düzeltme (^) işaretinin hangi konumda olduğunu görebiliriz. Ancak "geçersiz karakter" çoğu zaman görünmez bir karakter anlamına gelir, yalnızca onaltılık düzenleyici ile bulunur. En iyisi tüm satırı kaldırmak ve tekrar yazmaktır.
Hangi editör veya IDE'yi kullanıyorsunuz? Bazıları otomatik olarak bir metin dosyasının başına bir Malzeme Listesi (Byte Order Mark) ekler.

BBcode, bir Markdown dilidir, IDE'nizin bir parçası değildir
Reply
#6
Read this: Visual Studio UTF8 BOM support. BOM must be switched off.
Reply
#7
Pls help. I can't bind sql Python in Vscode


result :
import mysql.connector
^
SyntaxError: invalid character in identifier
Reply
#8
+help
Reply
#9
Quote:
result :
import mysql.connector
^
  • What is the upcarat on line 3? try removing it
  • Try again
  • If you still get error after fixing that, delete the import statement and retype manually and save
  • Try again
Reply
#10
(Mar-16-2020, 08:49 PM)Larz60+ Wrote: What is the upcarat on line 3? try removing it
The upcarat is the pointer that points to the place where the error is detected. So I believe there are invisible characters at the beginning of the file.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexplained Invalid syntax Error cybertooth 5 149 Yesterday, 10:05 AM
Last Post: cybertooth
  I have a syntax error! rohes_kaugummi 3 339 Jun-23-2021, 05:24 PM
Last Post: deanhystad
  import module with syntax error Skaperen 7 375 Jun-22-2021, 10:38 AM
Last Post: Skaperen
Heart near "(": syntax error Maryan 3 501 Jun-21-2021, 08:05 AM
Last Post: ibreeden
Exclamation getting a syntax error and i don't know why ilikedofs 10 795 May-13-2021, 08:52 PM
Last Post: deanhystad
  Even number code syntax error MrCeez 1 427 May-02-2021, 06:43 PM
Last Post: Larz60+
  error in your SQL syntax Xuli 10 740 May-02-2021, 12:27 PM
Last Post: Xuli
  Function syntax error Changosoyyo 2 568 Mar-07-2021, 10:42 PM
Last Post: Changosoyyo
  Syntax error on line 29 manwithjeans 3 630 Feb-27-2021, 08:28 AM
Last Post: perfringo
  Invalid syntax error - need help fixing calgk01 3 684 Feb-23-2021, 08:41 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020