0

I'm trying a SELECT using pymysql and I keep getting error: [Errno 32] Broken pipe. What am I missing? Everything works fine on my local machine, taking it to production breaks. I'm running an EC2 Micro instance.

    `import pymysql
    def connection():
      db = pymysql.connect(host='localhost', port=3306, user='**', 
          passwd='**',db='blog',charset='utf8')
      cur = db.cursor()

      cur.execute('SET NAMES utf8;')
      cur.execute('SET CHARACTER SET utf8;')
      cur.execute('SET character_set_connection=utf8;')
      return (cur,db) #Returns both curson and connection`

Code to grab data

       `cur.execute("SELECT * FROM nse WHERE DATE(created_at) = 
       (SELECT DATE(created_at) FROM nse ORDER BY id DESC LIMIT 1)",)
    for r in cur.fetchall():
        STOCKS[r[2]] =dict(date=r[1],symbol=r[2],open=r[3],high=r[4],low=r[5],close=r[6],change=r[7],deals=r[8],units=r[9],value=r[10])
    return STOCKS`

What you pointed out was in C and doesn't quite meet my need. Thank you.

Cyberomin
  • 65
  • 1
  • 6
  • 1
    Show your database connection statement and your Python code executing the SELECT please. – Andrew Kloos Jan 27 '14 at 17:05
  • Hi Andrew, here's the connection code `import pymysql def connection(): db = pymysql.connect(host='localhost', port=3306, user='***', passwd='***', db='blog',charset='utf8') cur = db.cursor() cur.execute('SET NAMES utf8;') cur.execute('SET CHARACTER SET utf8;') cur.execute('SET character_set_connection=utf8;') return (cur,db)` and the query to retrieve data is `cur.execute("SELECT * FROM nse WHERE DATE(created_at) = (SELECT DATE(created_at) FROM nse ORDER BY id DESC LIMIT 1)",)` note. Thank you. – Cyberomin Jan 28 '14 at 09:47
  • 1
    hmmm - Hard to read it that way. Would you please edit your question and format that code in there? Also, did you see this? http://stackoverflow.com/questions/11866792/how-to-prevent-errno-32-broken-pipe – Andrew Kloos Jan 28 '14 at 12:08
  • Thanks. Your resource did help. I had to pass everything through a try statement. – Cyberomin Jan 28 '14 at 14:45

0 Answers0