Skip to content

Broken in 3.8 due to bad import from marrow/cgi #87

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

Closed
indistinctTalk opened this issue Jan 24, 2020 · 27 comments
Closed

Broken in 3.8 due to bad import from marrow/cgi #87

indistinctTalk opened this issue Jan 24, 2020 · 27 comments
Assignees
Labels
1.bug An error has been encountered that is preventing utilization. area:packaging The issue relates to the Python Packaging aspects of the project. org:external Issue identified with upstream dependency.

Comments

@indistinctTalk
Copy link

indistinctTalk commented Jan 24, 2020

Looks like it's broken on python 3.8.1 currently.

Installs fine:

❯ pip install marrow.mailer --user                                                                                                         
Collecting marrow.mailer
  Using cached https://files.pythonhosted.org/packages/8c/37/961103b20bad1a8af86fa67a53748c2bf26e9e242a79fa89dc762d374ea6/marrow.mailer-4.0.3-py2.py3-none-any.whl
Collecting marrow.util<2.0
  Using cached https://files.pythonhosted.org/packages/d2/19/630a0984ba6d5dc4432ed45d2c9ab8752542fa6ba1590a0e72d1fb742c2e/marrow.util-1.2.3.tar.gz
Installing collected packages: marrow.util, marrow.mailer
    Running setup.py install for marrow.util ... done
Successfully installed marrow.mailer-4.0.3 marrow.util-1.2.3

Running a script with the example code:

from marrow.mailer import Mailer, Message

mailer = Mailer(dict(
        transport = dict(
                use = 'smtp',
                host = 'localhost')))
mailer.start()

message = Message(author="[email protected]", to="[email protected]")
message.subject = "Testing Marrow Mailer"
message.plain = "This is a test."
mailer.send(message)

mailer.stop()
Traceback (most recent call last):
  File "/home/liam/projects/soc_siem_bi_integration/soc_scripts/cleanup.py", line 8, in <module>
    from marrow.mailer import Mailer, Message
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/mailer/__init__.py", line 12, in <module>
    from marrow.mailer.message import Message
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/mailer/message.py", line 21, in <module>
    from marrow.mailer.address import Address, AddressList, AutoConverter
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/mailer/address.py", line 12, in <module>
    from marrow.util.compat import basestring, unicode, unicodestr, native
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/util/compat.py", line 33, in <module>
    from cgi import parse_qsl
ImportError: cannot import name 'parse_qsl' from 'cgi' (/usr/lib/python3.8/cgi.py)

If I go diving into compat.py and change from cgi import parse_qsl to from urllib.parse import parse_qsl, it works fine. This is makes sense, given Python 3.8 notes:

parse_qs, parse_qsl, and escape are removed from the cgi module. They are deprecated in Python 3.2 or older. They should be imported from the urllib.parse and html modules instead.

I don't know the ramifications of using urllib.parse over html, though.

Util is archived, otherwise I would have raised the issue there /shrug.

@nphilipp
Copy link

nphilipp commented Mar 8, 2020

I don't know the ramifications of using urllib.parse over html, though.

It's just that parse_qs and parse_qsl live in urllib.parse, escape lives in html.

Util is archived, otherwise I would have raised the issue there /shrug.

Yeah, it's kinda odd that marrow.mailer still depends on it.

@amcgregor
Copy link
Member

I don't know the ramifications of using urllib.parse over html, though.

Given it's not even used, the solution here is removal of that dependency, which is primarily there to support Python 2 compatibility, which is no longer a desired feature or concern. There are no ramifications.

@amcgregor amcgregor self-assigned this Apr 22, 2020
@amcgregor amcgregor added 1.bug An error has been encountered that is preventing utilization. area:packaging The issue relates to the Python Packaging aspects of the project. labels Apr 22, 2020
@iamareebjamal
Copy link

Yes, parse_ is not present in this repo, because it is present in marrow.util. Which is indeed still used in quite a few places in the project https://github.com/marrow/mailer/search?q=marrow.util&unscoped_q=marrow.util

@amcgregor
Copy link
Member

@iamareebjamal Reference my recent comment on #90 — with a properly quoted search you find the summary included at the end of that comment. That is: virtually none of marrow.util is required, except the compatibility for Python 2, which can go away, and Bunch… which is just an over-engineered attribute access dictionary. Splitting the discussion, though, is quite unfortunate, on this. #90 locked.

This issue is an actual issue, where the other is not.

@iamareebjamal

This comment has been minimized.

@amcgregor

This comment has been minimized.

@tyoc213
Copy link

tyoc213 commented Apr 22, 2020

Looks like it's broken on python 3.8.1 currently.

Installs fine:

Indeed it installs fine but importing it causes this

$ python
Python 3.8.2 (default, Mar 26 2020, 15:53:00) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from marrow.mailer import Message, Delivery
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/mailer/__init__.py", line 12, in <module>
    from marrow.mailer.message import Message
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/mailer/message.py", line 21, in <module>
    from marrow.mailer.address import Address, AddressList, AutoConverter
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/mailer/address.py", line 12, in <module>
    from marrow.util.compat import basestring, unicode, unicodestr, native
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/util/compat.py", line 33, in <module>
    from cgi import parse_qsl
ImportError: cannot import name 'parse_qsl' from 'cgi' (/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/cgi.py)
>>> from marrow.mailer import Mailer, Message
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/mailer/__init__.py", line 12, in <module>
    from marrow.mailer.message import Message
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/mailer/message.py", line 21, in <module>
    from marrow.mailer.address import Address, AddressList, AutoConverter
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/mailer/address.py", line 12, in <module>
    from marrow.util.compat import basestring, unicode, unicodestr, native
  File "/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/site-packages/marrow/util/compat.py", line 33, in <module>
    from cgi import parse_qsl
ImportError: cannot import name 'parse_qsl' from 'cgi' (/home/tyoc213/miniconda3/envs/diccionario/lib/python3.8/cgi.py)

What would be the fastest way to go? for run in python 3.8? Install an older version? (guess not?)

@amcgregor
Copy link
Member

@tyoc213 Quick fix while I work on removing marrow.util, isolate that module and patch out the import; being unused, this should have zero impact on marrow.mailer operation. To find the on-disk path to the file to modify pip install e (yup, just the letter e) then run python -me marrow.util.compat. That'll spit out the on-disk path. Edit that file, comment out (or correct) the from cgi line.

@tyoc213
Copy link

tyoc213 commented Apr 22, 2020

Indeed
image

It work now, I wait for the

@GertBurger
Copy link

Any news on this?

@iamareebjamal

This comment has been minimized.

@amcgregor

This comment has been minimized.

@iamareebjamal

This comment has been minimized.

@amcgregor

This comment has been minimized.

@ghost

This comment has been minimized.

@ghost
Copy link

ghost commented Aug 18, 2020

@GertBurger I have switched to this fork https://github.com/LexMachinaInc/mailer https://github.com/LexMachinaInc/util which contains the "trivial" fix we mere mortals are not worthy to enjoy in the official package. I suggest you do the same unless you want to wait another 4 months for a non-update

@amcgregor
Copy link
Member

amcgregor commented Aug 18, 2020

Curiouser and curiouser. That person made the fork, didn't bother opening a PR. Go figure. Edit: and did it wrong. That's just icing on this cavalcade.

@ghost

This comment has been minimized.

@amcgregor

This comment has been minimized.

@amcgregor
Copy link
Member

@GertBurger Apologies for the fantastic signal:noise ratio on this issue today. Work is progressing on the next branch which is a complete modernization and update to make use of all modern Python 3 features, including type annotation, modern datatypes, and offers the opportunity for elimination of no longer needed legacy. As a singular developer working on a codebase in such wide use, careful attention is being paid towards making the update as non-breaking as possible.

The "hack and slash" fix (comment out one specific line in your copy) can be effective as a short-term solution, slightly longer-term is the bit of helpful pointer that bubbled out of the chatter, a fork that is patched. However, this is also stop-gap, and an approach entirely taken from the wrong direction.

@fiahil
Copy link

fiahil commented Sep 9, 2020

Hey everyone,

I ran into this issue today. Rather than switching to a fork, you can temporarily fix this error by adding these lines at the top of the file (before importing Mailer):

import sys  # isort:skip

sys.modules["cgi.parse_qsl"] = None

@GertBurger
Copy link

OT but it seems that there is also an issue with Python 3.9 as base64.encodestring() has been removed, should be a trivial fix.

I guess one can do a similar monkey patch to add it back...

@amcgregor
Copy link
Member

amcgregor commented Feb 17, 2022

Looks like my employer paid me to unarchive the repository and patch it. The develop branch of marrow.util successfully operates on Python 3.8 for our SMTP + Mailgun use of Mailer with this patch.

If you are utilizing requirements.txt to pin versions, you can pin marrow.util like this:

-e git+https://github.com/marrow/util.git@cbbc386f8411403953186bf78a9dfcd7cffc42fc#egg=marrow.util

Aside: I also just tested the import process retrieving references to Mailer, MailgunTransport, and SMTPTransport on Python 3.9.

Marking as closed.

@amcgregor amcgregor added the org:external Issue identified with upstream dependency. label Feb 17, 2022
@amcgregor
Copy link
Member

@GertBurger The encodestring reference was corrected in 32dde28.

@davfive
Copy link

davfive commented Feb 22, 2022 via email

@Marrin
Copy link

Marrin commented Sep 22, 2022

This seems to be patched but there is no release on the Python package index, so the original problem is still there when installing marrow.mailer via pip.

@bronikowski
Copy link

I just hit that issue today. It's still buggy on PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.bug An error has been encountered that is preventing utilization. area:packaging The issue relates to the Python Packaging aspects of the project. org:external Issue identified with upstream dependency.
Projects
None yet
Development

No branches or pull requests

10 participants