Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid UTF-8 code sequence

I'm trying to do a simple connect using a NuoDB database -

import pynuodb
connection = pynuodb.connect("DB", "servername", "adminaccount", "password", options={'schema': 'schemaname'})
cursor = connection.cursor()
thedata = open('file.pdf', 'rb').read()
sql = "update table set column = (?) where id = 1"
cursor.execute(sql, (thedata,))

in trying to load it's generating the following error -

INVALID_UTF8:  invalid UTF-8 code sequence

UPDATE - I've tried using both a BLOB or BINARY and both generate the same error. The documentation on the data types is found here -

http://doc.nuodb.com/display/doc/Binary+Data+Types

like image 357
whoisearth Avatar asked Dec 06 '25 16:12

whoisearth


1 Answers

The pynuodb library gives you a special type to encapsulate binary data, pynuodb.Binary(); wrap binary data in that object to ensure correct handling:

thedata = pynuodb.Binary(open('file.pdf', 'rb').read())
sql = "update table set column = (?) where id = 1"
cursor.execute(sql, (thedata,))

Without this wrapper, the driver tries to send the data to the server as text, which must be UTF-8 encoded.

like image 82
Martijn Pieters Avatar answered Dec 08 '25 05:12

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!