TypeError: __init__() takes 1 positional argument but 4 were given

1,058 views
Skip to first unread message

shyam sundar sharma

unread,
Sep 7, 2022, 1:31:28 AM9/7/22
to openpyxl-users
Dear community,
I tried to open excel file with the engine openpyxl. I am getting one error - TypeError: __init__() takes 1 positional argument but 4 were given. Can you please tell me what should i do?

Please refer the error below -
df =pd.read_excel("C:\\Users\\SHAR8263\\Desktop\\check.xlsx", engine ='openpyxl')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-5a23dd753d78> in <module>
----> 1 df =pd.read_excel("C:\\Users\\SHAR8263\\Desktop\\check.xlsx", engine ='openpyxl')

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    309                     stacklevel=stacklevel,
    310                 )
--> 311             return func(*args, **kwargs)
    312
    313         return wrapper

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, decimal, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
    455     if not isinstance(io, ExcelFile):
    456         should_close = True
--> 457         io = ExcelFile(io, storage_options=storage_options, engine=engine)
    458     elif engine and engine != io.engine:
    459         raise ValueError(

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\pandas\io\excel\_base.py in __init__(self, path_or_buffer, engine, storage_options)
   1417         self.storage_options = storage_options
   1418
-> 1419         self._reader = self._engines[engine](self._io, storage_options=storage_options)
   1420
   1421     def __fspath__(self):

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\pandas\io\excel\_openpyxl.py in __init__(self, filepath_or_buffer, storage_options)
    523         """
    524         import_optional_dependency("openpyxl")
--> 525         super().__init__(filepath_or_buffer, storage_options=storage_options)
    526
    527     @property

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\pandas\io\excel\_base.py in __init__(self, filepath_or_buffer, storage_options)
    516             self.handles.handle.seek(0)
    517             try:
--> 518                 self.book = self.load_workbook(self.handles.handle)
    519             except Exception:
    520                 self.close()

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\pandas\io\excel\_openpyxl.py in load_workbook(self, filepath_or_buffer)
    534         from openpyxl import load_workbook
    535
--> 536         return load_workbook(
    537             filepath_or_buffer, read_only=True, data_only=True, keep_links=False
    538         )

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\openpyxl\reader\excel.py in load_workbook(filename, read_only, keep_vba, data_only, keep_links)
    315     reader = ExcelReader(filename, read_only, keep_vba,
    316                         data_only, keep_links)
--> 317     reader.read()
    318     return reader.wb

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\openpyxl\reader\excel.py in read(self)
    275     def read(self):
    276         self.read_manifest()
--> 277         self.read_strings()
    278         self.read_workbook()
    279         self.read_properties()

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\openpyxl\reader\excel.py in read_strings(self)
    142             strings_path = ct.PartName[1:]
    143             with self.archive.open(strings_path,) as src:
--> 144                 self.shared_strings = read_string_table(src)
    145
    146

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\openpyxl\reader\strings.py in read_string_table(xml_source)
     13     STRING_TAG = '{%s}si' % SHEET_MAIN_NS
     14
---> 15     for _, node in iterparse(xml_source):
     16         if node.tag == STRING_TAG:
     17             text = Text.from_tree(node).content

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\defusedxml\common.py in iterparse(source, events, parser, forbid_dtd, forbid_entities, forbid_external)
    103                   forbid_entities=True, forbid_external=True):
    104         if parser is None:
--> 105             parser = DefusedXMLParser(target=_TreeBuilder(),
    106                                       forbid_dtd=forbid_dtd,
    107                                       forbid_entities=forbid_entities,

C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\lib\site-packages\defusedxml\ElementTree.py in __init__(self, html, target, encoding, forbid_dtd, forbid_entities, forbid_external)
     66                  forbid_external=True):
     67         # Python 2.x old style class
---> 68         _XMLParser.__init__(self, html, target, encoding)
     69         self.forbid_dtd = forbid_dtd
     70         self.forbid_entities = forbid_entities

TypeError: __init__() takes 1 positional argument but 4 were given

Charlie Clark

unread,
Sep 7, 2022, 3:50:10 AM9/7/22
to openpyxl-users
On 7 Sep 2022, at 7:31, shyam sundar sharma wrote:

> Dear community,
>
> I tried to open excel file with the engine openpyxl. I am getting one error
>
> - TypeError: __init__() takes 1 positional argument but 4 were given. Can
>
> you please tell me what should i do?

First of all, if you think this is related to openpyxl, you should supply code using openpyxl. Much as I like Pandas, it doesn't help if you provide Pandas code.

However, looking at the traceback, it looks like the problem is possibly in DefusedXML. It also looks like you're using Python 2.7, which is no longer supported.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226

shyam sundar sharma

unread,
Sep 7, 2022, 4:52:34 AM9/7/22
to openpyxl-users
I tried to open code using openpyxl as well. But same error is showing up.
Please see the code below.
path ="C:\\Users\\SHAR8263\\Desktop\\check.xlsx"

wb_obj = openpyxl.load_workbook(path)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-1429798a3720> in <module>
----> 1 wb_obj = openpyxl.load_workbook(path)


I updated diffusedxml. I am using latest version of python.

These are the pip list -
Package                            Version
---------------------------------- ----------
altgraph                           0.17
argon2-cffi                        20.1.0
asn1crypto                         0.24.0
async-generator                    1.10
atomicwrites                       1.3.0
attrs                              21.2.0
autopep8                           1.4.4
backcall                           0.2.0
backports-abc                      0.5
backports.os                       0.1.1
backports.shutil-get-terminal-size 1.0.0
bleach                             4.1.0
build                              0.5.1
certifi                            2021.10.8
cffi                               1.14.5
charset-normalizer                 2.0.10
colorama                           0.4.4
comtypes                           1.1.10
cycler                             0.10.0
decorator                          5.0.9
defusedxml                         0.7.1
easygui                            0.98.1
entrypoints                        0.2.3
et-xmlfile                         1.1.0
html5lib                           1.0.1
idna                               3.3
importlib-metadata                 0.6
ipykernel                          5.5.5
ipython                            7.12.0
ipython-genutils                   0.2.0
ipywidgets                         7.4.2
jedi                               0.18.0
Jinja2                             3.0.3
jsonschema                         3.2.0
jupyter                            1.0.0
jupyter_client                     7.3.5
jupyter-console                    6.4.4
jupyter-contrib-core               0.3.3
jupyter-contrib-nbextensions       0.5.0
jupyter-core                       4.11.1
jupyter-highlight-selected-word    0.2.0
jupyter-latex-envs                 1.4.6
jupyter-nbextensions-configurator  0.4.0
jupyterlab-pygments                0.1.2
kiwisolver                         1.3.1
llvmlite                           0.35.0
lxml                               4.6.3
macholib                           1.11
MarkupSafe                         2.0.1
matplotlib                         3.4.2
matplotlib-inline                  0.1.2
mistune                            0.8.4
more-itertools                     7.2.0
nbclient                           0.5.3
nbconvert                          5.4.1
nbformat                           5.1.3
nest-asyncio                       1.5.5
notebook                           6.4.5
numba                              0.52.0
numpy                              1.22.2+mkl
openpyxl                           3.0.9
packaging                          21.0
pandas                             1.4.4
pandocfilters                      1.4.2
parso                              0.8.2
path.py                            11.5.0
pep517                             0.10.0
pep8                               1.7.0
pickleshare                        0.7.5
Pillow                             9.0.1
Pint                               0.9
pip                                22.2.2
pluggy                             0.6.0
prometheus-client                  0.11.0
prompt-toolkit                     3.0.19
psutil                             5.7.2
pycodestyle                        2.5.0
pycparser                          2.20
pycryptodome                       3.11.0
Pygments                           2.9.0
pyparsing                          2.4.7
pyperclip                          1.7.0
pypiwin32                          223
pyqtgraph                          0.12.1
pyreadline                         2.1
pyrsistent                         0.17.3
PySide2                            5.15.2
PySocks                            1.6.8
python-dateutil                    2.8.2
pythonnet                          2.5.2
pytz                               2022.2.1
pywin32                            301
pywin32-ctypes                     0.2.0
pywinpty                           1.1.2
PyYAML                             5.4.1
pyzmq                              23.2.1
qtconsole                          5.1.0
QtPy                               1.9.0
requests                           2.27.1
scipy                              1.6.3
Send2Trash                         1.5.0
setuptools                         60.5.0
shiboken2                          5.15.2
simplegeneric                      0.8.1
six                                1.16.0
terminado                          0.10.1
testpath                           0.4.2
toml                               0.10.2
tornado                            6.2
traitlets                          5.0.5
urllib3                            1.26.8
wcwidth                            0.1.7
webencodings                       0.5.1
wheel                              0.36.2
widgetsnbextension                 3.4.2
win-inet-pton                      1.0.1
win-unicode-console                0.5
wincertstore                       0.2
xlrd                               2.0.1



And python version is - 

(PLAXIS) C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python\Lib\site-packages>python --version
Python 3.8.10.


Please tell me what shall i do further?

Thank you,

Charlie Clark

unread,
Sep 7, 2022, 5:00:10 AM9/7/22
to openpyxl-users
On 7 Sep 2022, at 10:52, shyam sundar sharma wrote:

> I tried to open code using openpyxl as well. But same error is showing up.
>
> Please see the code below.

No, you should look at the exception. It's not coming from openpyxl.

Hiep Nguyen

unread,
Nov 14, 2022, 12:30:14 AM11/14/22
to openpyxl-users
I have the same error. 
Turn out the defusedxml package is out of dated. Upgrade it to version v0.7.1 
then it will work again.
Reply all
Reply to author
Forward
0 new messages