-3

I have defined my sql statement as follows ( note the line breaks)

  def getTankSystemIds():
        sql='select tt.TankSystemId,ts.sitecode,tt.productid ' \
            'from  [dbo].[TankSystems] tt' \
            'left join [dbo].sites ts on tt.siteid=ts.siteid where ts.companyid=8' \
            'and ProductId in (10,4,2,3,11,4)'
        cursor = connectDB()
        cursor.execute(sql)
        records = cursor.fetchall()

When calling this method, I get following error. I changed single quote to " and ''',""" but all gave same error What Im doing wrong here? I tried providing the sql statement in a single long line too. But same error

SyntaxError: Non-ASCII character '\xef' in file /Users/ratha/PycharmProjects/Processor/Utilities/DbConnector.py on line 86, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Ratha
  • 9,434
  • 17
  • 85
  • 163
  • 1
    It looks like you are missing some spaces, first of all. After tt and between left join, then between companyid=8 and AND productID. The error is something with how you are escaping/not escaping your slashes. If you put the SQL in one line with no slashes, should be fine. – dfundako Jun 27 '19 at 13:09
  • @dfundako No..it is not spaces are there.I tried again putting in one line didnt work either – Ratha Jun 27 '19 at 13:11
  • Your SQL is invalid. With no space, your first table alias becomes ttleft, not tt. So when you reference tt.siteid, it will fail. – dfundako Jun 27 '19 at 13:16

1 Answers1

0

Is the SQL query being copy/pasted from somewhere or saved as UTF-8 encoding by another program? It has a Byte Order Mark (BOM) which is what the \xef character is. ASCII doesn't like that because it's a Unicode thing.

Alex W
  • 37,233
  • 13
  • 109
  • 109