How do I write an image to Dropbox directly? - python

I'm trying to reduce read/write on my sd card by writing image files to DropBox directly. I captured the image into stream, but I don't know how to write it to Dropbox. This is with the raspberry pi.
dbx = dropbox.Dropbox('token')
stream = io.BytesIO()
with picamera.PiCamera() as camera:
camera.resolution = (1280,960)
camera.capture(stream,format='jpeg')
stream.seek(0)
im = Image.open(stream)
dbx.files_upload(im,"/test.jpg",mute=True)
i get the following error, but not sure what it means or how to fix it.
Traceback (most recent call last):
File "./camera.py", line 25, in <module>
dbx.files_upload(im,"/test.jpg",mute=True)
File "/usr/local/lib/python2.7/dist-packages/dropbox/base.py", line 1225, in files_upload
f,
File "/usr/local/lib/python2.7/dist-packages/dropbox/dropbox.py", line 249, in request
timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/dropbox/dropbox.py", line 341, in request_json_string_with_retry
timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/dropbox/dropbox.py", line 385, in request_json_string
type(request_binary))
TypeError: expected request_binary as binary type, got <type 'instance'>

Related

Odoo 12CE Print QR Code in POS receipt XmlReceipt template

I'am trying to print a QR code in the XmlReceipt (ESCPOS printed receipt) template but I'm getting this error printed in the actual receipt:
Traceback (most recent call last):
File "/home/pi/odoo/addons/hw_escpos/controllers/main.py", line 169, in run
printer.receipt(data)
File "/home/pi/odoo/addons/hw_escpos/escpos/escpos.py", line 717, in receipt
raise e
File "/home/pi/odoo/addons/hw_escpos/escpos/escpos.py", line 704, in receipt
print_elem(stylestack,serializer,root)
File "/home/pi/odoo/addons/hw_escpos/escpos/escpos.py", line 594, in print_elem
print_elem(stylestack,serializer,child)
File "/home/pi/odoo/addons/hw_escpos/escpos/escpos.py", line 594, in print_elem
print_elem(stylestack,serializer,child)
File "/home/pi/odoo/addons/hw_escpos/escpos/escpos.py", line 680, in print_elem
self.print_base64_image(bytes(elem.attrib['src'], 'utf-8'))
File "/home/pi/odoo/addons/hw_escpos/escpos/escpos.py", line 445, in print_base64_image
img_rgba = Image.open(f)
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2687, in open
% (filename if filename else fp))
OSError: cannot identify image file <_io.BytesIO object at 0x6b132f00>
I'm copying the exact same solution as Saudi Arabia module https://github.com/odoo/odoo/blob/14.0/addons/l10n_sa_pos/, and I already check that is rendering correctly at this step https://github.com/odoo/odoo/blob/12.0/addons/point_of_sale/static/src/js/screens.js#L1653
print_xml: function() {
var receipt = QWeb.render('XmlReceipt', this.get_receipt_render_env());
this.pos.proxy.print_receipt(receipt);
this.pos.get_order()._printed = true;
},
the image is sent as base64 svg+xml format and I already installed the iotboxv21_04 version. So I suspect that probably the pillow version 5.4.1 (which I already check that comes with that IoTbox version) can't open the SVG file type that was sent. Should I send it in PNG? how can I achieve that?

Coudl not find video device with name [integrated camera]amoung source devices of type video

Im testing aiortc becouse i wanna stream webcam audio and video to browser but when im trying to run webcam.py i get I/O error I/O error: 'video=Integrated Camera'
CODE IS HERE on github
Traceback (most recent call last):
File "C:\Users\user\Desktop\New folder\env\lib\site-packages\aiohttp\web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "C:\Users\user\Desktop\New folder\env\lib\site-packages\aiohttp\web_app.py", line 499, in _handle
resp = await handler(request)
File "webcam.py", line 69, in offer
audio, video = create_local_tracks(args.play_from)
File "webcam.py", line 36, in create_local_tracks
"video=Integrated Camera", format="dshow", options=options
File "C:\Users\user\Desktop\New folder\env\lib\site-packages\aiortc\contrib\media.py", line 238, in __init__
self.__container = av.open(file=file, format=format, mode="r", options=options)
File "av\container\core.pyx", line 355, in av.container.core.open
File "av\container\core.pyx", line 226, in av.container.core.Container.__cinit__
File "av\container\core.pyx", line 258, in av.container.core.Container.err_check
File "av\error.pyx", line 336, in av.error.err_check
av.error.OSError: [Errno 5] I/O error: 'video=Integrated Camera'
Okey if you get this error you need to check names of your devices with ffmpeg
windows
ffmpeg -list_devices true -f dshow -i dummy
linux
v4l2-ctl --list-devices
and get correct names for your devices and change them accordingly

How can read Minecraft .mca files so that in python I can extract individual blocks?

I can't find a way of reading the Minecraft world files in a way that i could use in python
I've looked around the internet but can find no tutorials and only a few libraries that claim that they can do this but never actually work
from nbt import *
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
I expected this to work but instead I got errors about the file not being compressed or something of the sort
Full error:
Traceback (most recent call last):
File "C:\Users\rober\Desktop\MinePy\MinecraftWorldReader.py", line 2, in <module>
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 628, in __init__
self.parse_file()
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 652, in parse_file
type = TAG_Byte(buffer=self.file)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 99, in __init__
self._parse_buffer(buffer)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 105, in _parse_buffer
self.value = self.fmt.unpack(buffer.read(self.fmt.size))[0]
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 276, in read
return self._buffer.read(size)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 463, in read
if not self._read_gzip_header():
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\x00\x00')
Use anvil parser. (Install with pip install anvil-parser)
Reading
import anvil
region = anvil.Region.from_file('r.0.0.mca')
# You can also provide the region file name instead of the object
chunk = anvil.Chunk.from_region(region, 0, 0)
# If `section` is not provided, will get it from the y coords
# and assume it's global
block = chunk.get_block(0, 0, 0)
print(block) # <Block(minecraft:air)>
print(block.id) # air
print(block.properties) # {}
https://pypi.org/project/anvil-parser/
According to this page, the .mca files is not totally kind of of NBT file. It begins with an 8KiB header which includes the offsets of chunks in the region file itself and the timestamps for the last updates of those chunks.
I recommend you to see the offical announcement and this page for more information.

ValueError: reading array data - while loading pickle file using joblib

I am trying to load a pickle file which i created using joblib.dump()
The dumping code looks like:
from sklearn.externals import joblib
with open('sample.pickle','wb') as f:
joblib.dump([x,y],f)
This works fine and my sample.pickle is saved successfully. But when i try to load this file:
with open('sample.pickle', 'rb') as f:
x, y = joblib.load(f)
I get the following error:
ValueError: EOF: reading array data, expected 1200 bytes got 0
The full error log looks like this:
Traceback (most recent call last):
File "model.py", line 16, in <module>
vec_x, vec_y = joblib.load(f)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 568, in load
obj = _unpickle(fobj)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 508, in _unpickle
obj = unpickler.load()
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\pickle.py", line 1050, in load
dispatch[key[0]](self)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 341, in load_build
self.stack.append(array_wrapper.read(self))
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 184, in read
array = self.read_array(unpickler)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 135, in read_array
read_size, "array data")
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle_utils.py", line 646, in _read_bytes
raise ValueError(msg % (error_template, size, len(data)))
ValueError: EOF: reading array data, expected 1200 bytes got 0
By the way, i am very new to dumping and pickling.
Any help will be appreciated. Thanks in advance.

Dropbox Python API: File size detection may have failed

I'm attempting to upload a text file to Dropbox using this code:
def uploadFile(file):
f = open('logs/%s.txt' % file)
response = client.put_file('/%s.txt' % file, f)
print "Uploaded log file %s" % file
Connecting to dropbox works perfectly fine, it's just when I upload files I recieve this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\dropbox_python_sdk-1.5.1-py2.7.egg\dropbox
\client.py", line 352, in put_file
return self.rest_client.PUT(url, file_obj, headers)
File "C:\Python27\lib\site-packages\dropbox_python_sdk-1.5.1-py2.7.egg\dropbox
\rest.py", line 265, in PUT
return cls.IMPL.PUT(*n, **kw)
File "C:\Python27\lib\site-packages\dropbox_python_sdk-1.5.1-py2.7.egg\dropbox
\rest.py", line 211, in PUT
return self.request("PUT", url, body=body, headers=headers, raw_response=raw
_response)
File "C:\Python27\lib\site-packages\dropbox_python_sdk-1.5.1-py2.7.egg\dropbox
\rest.py", line 174, in request
raise util.AnalyzeFileObjBug(clen, bytes_read)
dropbox.util.AnalyzeFileObjBug:
Expected file object to have 18 bytes, instead we read 17 bytes.
File size detection may have failed (see dropbox.util.AnalyzeFileObj)
Google has given me no help with this one.
Sounds like you are a victim of newline unification. The file object reports a file size of 18 bytes ("abcdefghijklmnop\r\n") but you read only 17 bytes ("abcdefghijklmnop\n").
Open the file in binary mode to avoid this:
f = open('logs/%s.txt' % file, 'rb')
The default is to use text mode, which may convert '\n' characters to a platform-specific representation on writing and back on reading.

Categories

Resources