Home > other >  Python read essentially a database image field problems ~
Python read essentially a database image field problems ~

Time:09-19

Shown in the following code, need to read the content of the image field, only read a row, but prompt error, error is as follows:
Ok
The Dataset linked
[(u'\xb0\xcd10', datetime.datetime(2020, 4, 24, 0, 6, 16), 0, 4.81, None, '\x00\x00\x00\x00\x02\xfdo-\x1e\xb8J\xe6e\x00\x00G\xb1\x00\xdbM\x9f\x00\xdbT\x80\x02\x91Z\x00\x03l`s\x04Gf\x1f\x05\xfej\xad\x07\xb4n\xfa\tjr\xd8\x0b!t\xe8\x0c\xd7wP\x0fiy\xcf\x11\x1f|\xd1\x13\xb1\x81\x1d\x16B\x87\xd2\x18\xd4\x90\x12\x1be\x98=\x1e\xd2\xa0Q!d\xa7\xb6$\xd0\xae\x12(=\xb2\x8b*\xcf\xb6\xd7.;\xbb91\xa8\xbf\xde5\x15\xc4\x828\x81\xca\xb3;\xee\xd2\x17?[\xdb`B\xc8\xe6aEY\xf1\x1fI\xa1\xf9\x8cM\xe9\xfe\xf6QV\xff\xffU\x9e\xfc Y\xe5\xf5*^-\xedma\x9a\xe5\x85e\xe2\xde\x8ej*\xd8\xccm\x97\xd35r\xba\xcd\xcbv&\xc7\x84zn\xbf\xb2}\xdb\xb7\x19\x82#\xafs\x86k\xa8\xea\x89\xd8\xa5z\x8e\x1f\xa5\xbc\x91\x8c\xa9X\x94\xf9\xaeT\x99A\xb4\xb1\x9c\xae\xbas\xa0\x1a\xbe\xc0\xa3\x87\xc1\xd8\xa6\xf4\xc4\x98\xaa`\xc7,\xae\xa8\xca\x9d\xb2\x15\xcf+\xb5\x82\xd4\x7f\xb8\x13\xd9\xea\xbb\x80\xde\n\xbe\x12\xdfT\xc1~\xde\n\xc4\x10\xdaB\xc7}\xd4\'\xca\xe9\xcd\x9f\xcd{\xc8J\xd0\xe8\xc3\xfe\xd3y\xc1(\xd6\x0b\xbfp\xd8\x9c\xbd\x8c\xdb.\xbb#\xdd\xbf\xb7\xc9\xdfv\xb3}\xe2\x07\xafG\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:1\xa8\x1b\x82/\x16\x19\x9d+\xaa\x18\x7f(=\x18i%\xab\x1a\xe7"?\x1e\xdc\x1f\xad#\xac\x1d\x1c)C\x1a\x8a/\x1b\x17\xf93Q\x15g6j\x12\xd58\x90\x11\x1f:\x06\x0e\x8e;$\x0c\xd7=`\x0b!?\xb2\tjA\xc2\x07\xb4B\xf6\x05\xfeC"\x05#A\xc2\x04G?\x86\x02\x91<\xc6\x01\xb69\xae\x00\xdb7\x04\x00\xdb6\x96\x00\x007\x1a\x00\x008\xd2\x00\x00:\xf8\x00\x00?.\x00\x00B\xf6', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.989989995956421, 45.1199951171875, 74.89999389648438, False, True, None, None, 0.0, 1.0, -4, None, 1.0, None, None, None, None, None, None, None, None, None, None, None, None)]

Traceback (the most recent call last) :
The File "C: \ Users \ \ Administrator \ Desktop \ readimage1 py", 48, the line in & lt; module>
Img=Image. Open (img_file)
The File "C: \ Python27 \ lib \ site - packages \ PIL \ Image py", line 2309, in the open
% (filename if filename else fp))
IOError: always identify the image file & lt; _io. BytesIO object at 0 x07b49720 & gt;
The Dataset is the content of the linked below I print out the record's content, the most to read is the sixth field 2 content, error message as shown above, and specific code is as follows:

# coding=utf-8
The import IO
The import pymssql
The import matplotlib. Pyplot as the plot
The import numpy as np
The from PIL import Image

The class MSSQL:
Def __init__ (self, host, user, PWD, db) :
The self. The host=host
The self. The user=user
Self. PWD=PWD
The self. The db=db

Def __GetConnect (self) :
If not the self. The db:
Raise (NameError, "not set up the database information")
Self. Conn=pymssql. Connect (host=self. The host, user=self. The user and password=self. PWD, database=self. The db, charset="utf8")
Cur=self. Conn. Cursor ()
If not cur:
Raise (NameError, "connect to the database failed")
The else:
Print (" Dataset linked ")
Return a cur

Def ExecQuery (self, SQL) :
Cur=self. __GetConnect ()
Cur. Execute (SQL)
ResList=cur. Fetchall ()

# after the query must close the connection
Self. Conn. Close ()
Return resList

Def ExecNonQuery (self, SQL) :
Cur=self. __GetConnect ()
Cur. Execute (SQL)
MIT ()
self.conn.comSelf. Conn. Close ()



Ms=MSSQL (host="* *", the user="* *", the PWD="* *", db="* *")
Print (" ok ")
Reslist=Ms. ExecQuery (" select top 1 * from table1 ")
Img_file=IO. BytesIO (reslist [0] [5]) image data item # representing
Print reslist
Img=Image. Open (img_file)
The plot. The figure ()
The plot. Imshow (img, cmap="gray_r")
The plot. The show ()
The master know what reason, solve,,,

CodePudding user response:

Don't change to sink, master and have a look, ~ ~

CodePudding user response:

Is anyone here? Is anyone here?

CodePudding user response:

The master knows what's the problem?

CodePudding user response:

Python2 environment, python3 code
  • Related