Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected keyword argument 'delete' #158

Open
bvj opened this issue May 20, 2022 · 13 comments
Open

unexpected keyword argument 'delete' #158

bvj opened this issue May 20, 2022 · 13 comments

Comments

@bvj
Copy link

bvj commented May 20, 2022

Hi, i am trying import wp xml file, but getting error.

Wagtail ID: 5, About, updated
Wagtail ID: 6, Call for Members, updated
Wagtail ID: 7, Contact, updated
Wagtail ID: 8, Constitution, updated
Wagtail ID: 9, Open Data, updated
Wagtail ID: 10, Members, updated
Wagtail ID: 11, INSPIRE Hack 2017, updated
Exception ignored in: <function TemporaryFile.__del__ at 0x000002142879B010>
Traceback (most recent call last):
  File "C:\w\wp\env\lib\site-packages\django\core\files\temp.py", line 61, in __del__
    self.close()
  File "C:\w\wp\env\lib\site-packages\django\core\files\temp.py", line 49, in close
    if not self.close_called:
AttributeError: 'TemporaryFile' object has no attribute 'close_called'
Traceback (most recent call last):
  File "C:\w\wp\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\w\wp\env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\w\wp\env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\w\wp\env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\w\wp\env\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\management\commands\import_xml.py", line 70, in handle
    importer.run(
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\importers\wordpress.py", line 113, in run
    wp_post_id=wordpress_item.cleaned_data.get("wp_post_id")
  File "C:\p\Python310\lib\functools.py", line 981, in __get__
    val = self.func(instance)
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\importers\wordpress.py", line 518, in cleaned_data
    "body": self.body_stream_field(self.prefilter_content(self.raw_body)),
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\importers\wordpress.py", line 437, in body_stream_field
    blocks_dict = builder.build()
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\block_builder.py", line 123, in build
    cached_fallback_value = cached_fallback_function(
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\block_builder_defaults.py", line 284, in build_richtext_block_content
    html = image_linker(html)
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\block_builder_defaults.py", line 92, in image_linker
    saved_image = get_or_save_image(image_src)
  File "C:\w\wp\env\lib\site-packages\wagtail_wordpress_import\block_builder_defaults.py", line 124, in get_or_save_image
    temp_image = NamedTemporaryFile(delete=True)
TypeError: TemporaryFile.__init__() got an unexpected keyword argument 'delete'
@nickmoreton
Copy link
Collaborator

Not seen that error before.

Can you tell me about your Python, Django and Wagtail versions in use?

@bvj
Copy link
Author

bvj commented May 20, 2022

Python 3.10.2
Django 3.2.13
Wagtail 2.16.2
CodeRedCms 0.23.0

@nickmoreton
Copy link
Collaborator

Looks like you are using windows and virtual env which shouldn't be an issue.

Can you try this test setup with your XML file, it runs in docker and on gitpod.io https://gitpod.io/#github.com/nickmoreton/wwi-docker-develop

You can copy in your XML file and run the import on it.

@nickmoreton
Copy link
Collaborator

nickmoreton commented May 20, 2022

CodeRedCms 0.23.0

We haven't tried it on CoderedCms but I don't think that would be the cause.

@nickmoreton
Copy link
Collaborator

temp_image = NamedTemporaryFile(delete=True) is used when an image is been imported. I'd check the XML for that particular import to see if there are any clues there.

@nickmoreton
Copy link
Collaborator

Python 3.10.2

Is not tested on the released package but: #157 is soon to be released for Wagtail 3.0+ and includes Python 3.10

@bvj
Copy link
Author

bvj commented May 20, 2022

I uploaded xml to gitpod.
cms/plan4all.xml
But unable to try import:
python manage.py import_xml plan4all.xml 1
Traceback (most recent call last):
File "manage.py", line 8, in
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

@nickmoreton
Copy link
Collaborator

nickmoreton commented May 20, 2022

Try:

fab sh
cd cms
./manage.py delete_imported_pages pages PostPage
./manage.py import_xml ../xml/your_xml_file.xml 3

fab sh: gets you into the container which is where you need to run the commands from, thats why you are seeing ModuleNotFoundError: No module named 'django'

You could put your xml file anywhere and use the path to it's location.

The page id 3 is the default home page

@bvj
Copy link
Author

bvj commented May 20, 2022

Different error

root@13fb4dc687b5:/app/cms# ./manage.py import_xml plan4all.xml 3
Wagtail ID: 78, About, created
Wagtail ID: 79, Call for Members, created
Wagtail ID: 80, Contact, created
Wagtail ID: 81, Constitution, created
Wagtail ID: 82, Open Data, created
Wagtail ID: 83, Members, created
Wagtail ID: 84, INSPIRE Hack 2017, created
Wagtail ID: 85, References, created
Wagtail ID: 86, Projects, created
Wagtail ID: 87, Mentors at the Kampala INSPIRE Hackathon 2020, created
Wagtail ID: 88, Pilsen Open 2017, created
Wagtail ID: 89, Prague INSPIRE Hack 2018, created
Wagtail ID: 90, ORLÉANS/OGC INSPIRE Hackathon 2018, created
Wagtail ID: 91, PoliVisu, created
Wagtail ID: 92, EUXDAT, created
Wagtail ID: 93, Data Protection Policy, created
Wagtail ID: 94, Valmiera INSPIRE Hackathon 2018, created
Wagtail ID: 95, INSPIRE Hackathon 2018, created
Wagtail ID: 96, API, created
Wagtail ID: 97, Committee, created
Wagtail ID: 98, INSPIRE Hackathon 2016, created
Wagtail ID: 99, Prague INSPIRE Hackathon 2019, created
Wagtail ID: 100, EO4Agri, created
Wagtail ID: 101, INSPIRE Hackathon, created
Wagtail ID: 102, Nairobi INSPIRE Hackathon 2019, created
Wagtail ID: 103, Patras DataBio Hackathon 2019 - AI for Agriculture, created
Wagtail ID: 104, PoliRural, created
Wagtail ID: 105, SIEUSOIL, created
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 36839, column 1152

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/app/wagtail-wordpress-import/wagtail_wordpress_import/management/commands/import_xml.py", line 70, in handle
    importer.run(
  File "/app/wagtail-wordpress-import/wagtail_wordpress_import/importers/wordpress.py", line 94, in run
    xml_doc.expandNode(node)
  File "/usr/local/lib/python3.8/xml/dom/pulldom.py", line 254, in expandNode
    event = self.getEvent()
  File "/usr/local/lib/python3.8/xml/dom/pulldom.py", line 266, in getEvent
    self.parser.feed(buf)
  File "/usr/local/lib/python3.8/xml/sax/expatreader.py", line 221, in feed
    self._err_handler.fatalError(exc)
  File "/usr/local/lib/python3.8/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:36839:1152: not well-formed (invalid token)

@nickmoreton
Copy link
Collaborator

xml.sax._exceptions.SAXParseException: :36839:1152: not well-formed (invalid token)

I suspect the XML is problematic at line 36839

I did a search for it: xml.sax._exceptions.SAXParseException: :36839:1152: not well-formed (invalid token) that could help you.

@nickmoreton
Copy link
Collaborator

Reduce XML command could help, it removes the comments, that could be where the above is introduced. Of course if you need the comments that won't help 😞

@nickmoreton
Copy link
Collaborator

Might I suggest: https://wagtailcms.slack.com/archives/C02NB3SJDL3 where other people could help.

@jlchilders11
Copy link

I looked into this a bit myself, since I was experiencing the same issue. It seems that the Django implementation of NamedTemporaryFile has special logic on windows only. Part of this special logic is that it does not accept the Delete keyword: https://github.com/django/django/blob/4bf4222010fd8e413963c6c873e4088614332ef9/django/core/files/temp.py#L34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants