Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7952467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:52:14+00:00 2026-06-04T02:52:14+00:00

I have written a python script to parse an HTML page, get some strings

  • 0

I have written a python script to parse an HTML page, get some strings and then write to a mysql table. I am using the MySQLDb module for the database connection.
The strings retrieved are encoded in ISO-8859-7 (Greek), which is the default encoding in the MySQL table as well. The code which produces the exception is the following :

  def db_write(list) :
    import MySQLdb as sql
    try :
        con = sql.connect(//database info here//)
    except :
        print "could not connect to database"
        exit()
    cur = con.cursor()
    for i in my_range (8,len(list)-2,2) :
        query = 'INSERT INTO as_doy VALUES (%s,"%s")' % (list[i],list[i+1])
        print query        
        try :
            cur.execute(query)
            con.commit()
        except :
            print "failed"
            con.rollback()
    con.close()

The exception i get is ERROR 1366 (HY000): Incorrect string value: '\xEF\xBF\xBD\xEF\xBF\xBD...'

I have tried encoding the strings in utf-8, decoding and re-encoding in iso-8859-7, but nothing has worked for me yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:52:15+00:00Added an answer on June 4, 2026 at 2:52 am

    Make sure your connection collation is correct by passing the charset argument to .connect() or execute SET NAMES utf8 (or equivalent) before you run any queries.

    For more tips, see this link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the past, I have written a script using the Python IMAP library to
Greetings. I have written a little python script that calls MySQL in a subprocess.
i have written this python program. whenever i run the script using parameters like
I have written a CGI script that creates an image dynamically using GET data.
I have written a python script which watches a directory for new subdirectories, and
I have written a python script with methods in it. Now I want to
I have a mechanize script written in python that fills out a web form
I have written a python program with a PyQt GUI that, using the imaplib,
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create
I have written a python script which read from a txt file and perform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.