pyexcel suddenly no longer opens .xlsx (or .xls) - pyexcel

I have all the necessary dependencies installed:
pyexcel==0.7.0
pyexcel-ezodf==0.3.4
pyexcel-io==0.6.6
pyexcel-ods3==0.6.1
pyexcel-xls==0.7.0
(and some others, which I've omitted). Last week, my code was working. Now I am unable to open the very same .xls
>>> p = Path("data/jr1305221.xls")
>>> p.exists()
True
>>> pyexcel.get_book(file_name=p)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\core.py", line 47, in get_book
book_stream = sources.get_book_stream(**keywords)
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\core.py", line 36, in get_book_stream
a_source = SOURCE.get_book_source(**keywords)
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\source_plugin.py", line 85, in get_book_source
return self.get_a_plugin(
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\source_plugin.py", line 69, in get_a_plugin
source_cls = self.load_me_now(
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\source_plugin.py", line 41, in load_me_now
if source.is_my_business(action, **keywords):
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\plugins\__init__.py", line 56, in is_my_business
raise IOError("Unsupported file type")
OSError: Unsupported file type
>>>
or .xlsx
>>> p = Path('data/dummy.xlsx')
>>> p.exists()
True
>>> pyexcel.get_book(file_name=p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\core.py", line 47, in get_book
book_stream = sources.get_book_stream(**keywords)
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\core.py", line 36, in get_book_stream
a_source = SOURCE.get_book_source(**keywords)
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\source_plugin.py", line 85, in get_book_source
return self.get_a_plugin(
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\source_plugin.py", line 69, in get_a_plugin
source_cls = self.load_me_now(
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\internal\source_plugin.py", line 41, in load_me_now
if source.is_my_business(action, **keywords):
File "C:\Users\User McUser\AppData\Local\Programs\Python\Python310\lib\site-packages\pyexcel\plugins\__init__.py", line 56, in is_my_business
raise IOError("Unsupported file type")
OSError: Unsupported file type
>>>
Even in my docker container, it's stopped working.
As an alternative, I have also tried
with open('data/dummy.xlsx', 'r') as f:
pyexcel.get_book(file_name=f)
and get the same error.
I have read the docs again. I have rolled back my code to last week. What have I done to deserve this? Why has god forsaken me?

file_name needs to be a string, where I was passing in a pathlib.PosixPath
i.e., this returns the error:
p = Path('my_file')
pyexcel.get_book(file_name=p)
this works:
pyexcel.get_book(file_name='my_file')
You can use pyexcel.get_book(file_name=my_file.as_posix()) to get the string representation from the PosixPath.

Related

Python Keyerror 'sapi5', cant understand the error

One question of this type is previously asked but is not very helpful. I am using version Python3.8 in Windows 10 OS. I am getting an error, KeyError: 'sapi5'. dont know why this error is occurring. Please have a look at the below code given . My code is-
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[0].id)
The Error is quite big. can anyone help me?
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
from comtypes.gen import SpeechLib # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'ctypes.c_long'>, <class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.c_long'>, <class 'ctypes.c_long'>), 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "g:/saurav/Assistant/VA/MyAssistant.py", line 9, in <module>
engine = pyttsx3.init('sapi5')
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
engine = comtypes.client.CreateObject("SAPI.SpVoice")
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
mod = GetModule(tlib)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
mod = _my_import(fullname)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
return __import__(fullname, globals(), locals(), ['DUMMY'])
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 140, in <module>
ISpeechRecoGrammar._methods_ = [
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
self._make_methods(value)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
prototype = WINFUNCTYPE(restype, *argtypes)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 125, in WINFUNCTYPE
class WinFunctionType(_CFuncPtr):
TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.
first uninstall pyttsx3 using following command
pip uninstall pyttsx3
Then install pyttsx3 version 2.6 using following command
pip install pyttsx3==2.6

django-simple-history 1.9 break unittests

When I run unittests with django-simple-history==1.6.0, it runs fine but with
django-simple-history==1.9.0 it breaks the unittests.
Any ideas how to fix this?
Creating test database for alias 'default'...
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/me/venv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/me/venv/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/home/me/venv/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/home/me/venv/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/me/venv/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 376, in create_test_db
self.connection._test_serialized_contents = self.serialize_db_to_string()
File "/home/me/venv/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 413, in serialize_db_to_string
serializers.serialize("json", get_objects(), indent=None, stream=out)
File "/home/me/venv/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 129, in serialize
s.serialize(queryset, **options)
File "/home/me/venv/lib/python2.7/site-packages/django/core/serializers/base.py", line 52, in serialize
for obj in queryset:
File "/home/me/venv/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 409, in get_objects
for obj in queryset.iterator():
File "/home/me/venv/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/home/me/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 829, in execute_sql
cursor.execute(sql, params)
File "/home/me/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/me/venv/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/me/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/me/venv/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: myapp_historicalbook.history_change_reason
I got it. I had to remove my migration folder in order to be able to run the unit tests.

Expected binary or unicode string, got 0.0

I'm training my first model with TensorFlow, but I keep having this error:
Expected binary or unicode string, got 0.0
I followed TensorFlow linear model tutorial (https://www.tensorflow.org/tutorials/wide) and applied it on my own dataset.
This is what I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 289, in new_func
return func(*args, **kwargs)
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 455, in fit
loss = self._train_model(input_fn=input_fn, hooks=hooks)
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 953, in _train_model
features, labels = input_fn()
File "<stdin>", line 2, in train_input_fn
File "<stdin>", line 5, in input_fn
File "<stdin>", line 5, in <dictcomp>
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 102, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 473, in make_tensor_proto
append_fn(tensor_proto, proto_values)
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 109, in SlowAppendObjectArrayToTensorProto
tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values])
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 109, in <listcomp>
tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values])
File "/home/nick/anaconda3/lib/python3.6/site-packages/tensorflow/python/util/compat.py", line 65, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got 0.0
Any suggestion?
Thanks

WARNING: Readline services not available or not loaded.AttributeError: 'module' object has no attribute 'set_completer_delims'

REPL run ipython an error occurred.
WARNING: Readline services not available or not loaded.
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\Data\Packages/SublimeREPL/config/Python/ipy_repl.py", line 52, in <module>
embedded_shell.initialize()
File "<string>", line 2, in initialize
File "D:\Python27\lib\site-packages\IPython\config\application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "D:\Python27\lib\site-packages\IPython\terminal\ipapp.py", line 332, in initialize
self.init_shell()
File "D:\Python27\lib\site-packages\IPython\terminal\console\app.py", line 114, in init_shell
client=self.kernel_client,
File "D:\Python27\lib\site-packages\IPython\config\configurable.py", line 337, in instance
inst = cls(*args, **kwargs)
File "D:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 524, in __init__
self.init_completer()
File "D:\Python27\lib\site-packages\IPython\terminal\console\interactiveshell.py", line 129, in init_completer
self.Completer = ZMQCompleter(self, self.client, config=self.config)
File "D:\Python27\lib\site-packages\IPython\terminal\console\completer.py", line 37, in __init__
self.readline.set_completer_delims('\r\n')
AttributeError: 'module' object has no attribute 'set_completer_delims'
I experienced this problem whilst running ipython console in the WinPython distribution. In my case the problem was fixed by installing pyreadline:
pip install pyreadline
Hope this works for you too.

Send csv-file as attachment via MIMEBase - python

I don't get it. I try to send an e-mail with a csv-file as attachment. The first run with the script was fine, I recieved the e-mail with the csv-file as attachment. But after running it once, the script crashes with an odd Traceback message.
Heres my code so far:
import smtplib
import email.utils
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders
msg = MIMEMultipart('foo')
msg['To'] = email.utils.formataddr(('foo', 'foo#foobar.de'))
msg['From'] = email.utils.formataddr(('foo', 'foo#foo'))
msg['Subject'] = 'foo'
# Attach a file
mail_file = file('foo.csv').read()
mail_file = MIMEBase('application', 'csv')
mail_file.set_payload(mail_file)
mail_file.add_header('Content-Disposition', 'attachment', filename='foo.csv')
Encoders.encode_base64(mail_file)
msg.attach(mail_file)
# Define SMTP server
server = smtplib.SMTP('localhost')
server.set_debuglevel(True) # show communication with the server
# Send the mail
try:
server.sendmail('foo#foo', ['foo#foobar.de'], msg.as_string())
finally:
server.quit()
Now I get the following traceback:
Traceback (most recent call last):
File "mail.py", line 27, in <module>
Encoders.encode_base64(mail_file)
File "/usr/lib/python2.7/email/encoders.py", line 45, in encode_base64
encdata = _bencode(orig)
File "/usr/lib/python2.7/email/encoders.py", line 31, in _bencode
hasnewline = (s[-1] == '\n')
File "/usr/lib/python2.7/email/message.py", line 294, in __getitem__
return self.get(name)
File "/usr/lib/python2.7/email/message.py", line 360, in get
name = name.lower()
AttributeError: 'int' object has no attribute 'lower'
When I uncomment line 27 (Encoding Line), I get the following:
Traceback (most recent call last):
File "mail.py", line 33, in <module>
server.sendmail('foo#foo', ['foo#foobar.de'], msg.as_string())
File "/usr/lib/python2.7/email/message.py", line 137, in as_string
g.flatten(self, unixfrom=unixfrom)
File "/usr/lib/python2.7/email/generator.py", line 83, in flatten
self._write(msg)
File "/usr/lib/python2.7/email/generator.py", line 108, in _write
self._dispatch(msg)
File "/usr/lib/python2.7/email/generator.py", line 134, in _dispatch
meth(msg)
File "/usr/lib/python2.7/email/generator.py", line 203, in _handle_multipart
g.flatten(part, unixfrom=False)
File "/usr/lib/python2.7/email/generator.py", line 83, in flatten
self._write(msg)
File "/usr/lib/python2.7/email/generator.py", line 108, in _write
self._dispatch(msg)
File "/usr/lib/python2.7/email/generator.py", line 134, in _dispatch
meth(msg)
File "/usr/lib/python2.7/email/generator.py", line 177, in _handle_text
raise TypeError('string payload expected: %s' % type(payload))
TypeError: string payload expected: <type 'instance'>
Any ideas?
Strange, when I do
mail_file.set_payload(open('foo.csv', 'rb').read())
instead of
mail_file = file('foo.csv').read()
mail_file.set_payload(mail_file)
the Code works.. Still wondering why...!?