[sqlalchemy] UnicodeDecodeError when accessing PickleType column

2016-12-05 Thread Adam Pletcher
I'm upgrading one of our tools from Python 2.6.4 (SQLAlchemy 0.9.2) to 
Python 3.4.1 (SQLAlchemy 1.1.4), and hitting an error when accessing a 
PickleType column in one of the ORM classes.  This is on MS SQL Server 
2012, connecting with pyodbc, and client code running on Windows 8.1 64-bit.

This ORM class is for storing binary image data. The column in question is 
set to PickleType, with no constructor arguments like this:

sqlalchemy.Column( 'image_data', sqlalchemy.PickleType )

This turns into an "image" column type on the MS SQL server.  For a long 
time the Python 2.6 tool has populated objects with that column using code 
like this:

self.image_data = open( image_filename, 'rb' ).read( )

Then pulled those images back out to files like this:

image_file = open( image_filename, 'wb' ).write( self.image_data )

Since the upgrade that last "write" line throws a UnicodeDecodeError, on 
line 1478 of sqltypes.py, when it calls loads(value).  Stack trace pasted 
below.
It appears the "loads" call needs to use encoding='bytes' for it to 
succeed, but I'm not sure why or how to set it up to do that.  Is there a 
configuration parameter I'm missing?
I thought this might require using PickleType(protocol=2), but that made no 
difference.  That column is set up as deferred, but disabling that hits the 
same error.

Any suggestions appreciated.

- Adam

 File "d:\projects\ctg\python3\ctg\src\tools\vm_client\vm_client.pyw", 
line 1357, in 
  app.MainLoop( )
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\wx\core.py", 
line 1893, in MainLoop
  rv = wx.PyApp.MainLoop(self)
 File 
"d:\projects\ctg\python3\ctg\src\tools\vm_client\vmlib\views\entries.py", 
line 156, in on_item_selected
  self.parent.manager.callback_manager.call( vmlib.CB_LOAD_SCREENSHOTS, [ 
entry ] )
 File 
"d:\projects\ctg\python3\ctg\src\tools\vm_client\vmlib\core\callback.py", 
line 31, in call
  function( *args, **kwargs )
 File 
"d:\projects\ctg\python3\ctg\src\tools\vm_client\vmlib\views\screenshot.py", 
line 926, in load_screenshots
  ss.save_image( img_filename )
 File 
"d:\projects\ctg\python3\ctg\src\tools\vm_client\vmlib\core\database.py", 
line 471, in save_image
  image_file = open( image_filename, 'wb' ).write( self.image_data )
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\attributes.py",
 
line 237, in __get__
  return self.impl.get(instance_state(instance), dict_)
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\attributes.py",
 
line 584, in get
  value = self.callable_(state, passive)
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\strategies.py",
 
line 305, in _load_for_state
  only_load_props=group, refresh_state=state) is None:
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\loading.py",
 
line 223, in load_on_ident
  return q.one()
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\query.py",
 
line 2756, in one
  ret = self.one_or_none()
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\query.py",
 
line 2726, in one_or_none
  ret = list(self)
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\loading.py",
 
line 75, in instances
  rows = [proc(row) for row in fetch]
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\loading.py",
 
line 75, in 
  rows = [proc(row) for row in fetch]
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\loading.py",
 
line 437, in _instance
  loaded_instance, populate_existing, populators)
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\orm\loading.py",
 
line 498, in _populate_full
  dict_[key] = getter(row)
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\engine\result.py",
 
line 93, in __getitem__
  return processor(self._row[index])
File 
"d:\projects\ctg\python3\ctg\publish\python\lib\site-packages\sqlalchemy\sql\sqltypes.py",
 
line 1478, in process
  return loads(value)

builtins.UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in 
position 0: ordinal not in range(128)

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Connecting with Windows Auth?

2009-02-25 Thread Adam Pletcher

Is it possible to connect to a server using Windows Authentication
using sqlalchemy?

I have a MSSQL server database where my Windows account is needed to
create tables.  I didn’t turn up anything on the connection syntax for
this when I searched.
Thanks in advance.

- Adam

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---