Skip to content

bpo-46943: fix[imaplib]: call Exception with string instance #31722

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

Conversation

spaceone
Copy link

@spaceone spaceone commented Mar 7, 2022

Adjust the behavior of login similar to authenticate() where self.error is called with a str instance.

Especially for Python3 with strict bytes mode (-bb) this is helpful and prevents:

    Traceback (most recent call last):
      in "<stdin>"
        self.login(email, password)
      File "/usr/lib/python3.7/imaplib.py", line 598, in login
        raise self.error(dat[-1])
    imaplib.error: <exception str() failed>
    
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      in "<stdin>"
        str(exc)
    BytesWarning: str() on a bytes instance

https://bugs.python.org/issue46943

Adjust the behavior similar to `authenticate()` where self.error is
called with a str() instance.

Especially for Python3 with strict bytes mode (-bb) this is helpful and
prevents:

Traceback (most recent call last):
  in "<stdin>"
    self.login(email, password)
  File "/usr/lib/python3.7/imaplib.py", line 598, in login
    raise self.error(dat[-1])
imaplib.error: <exception str() failed>

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  in "<stdin>"
    str(exc)
BytesWarning: str() on a bytes instance
@spaceone spaceone force-pushed the imaplib-fix-exception-call-with-str branch from 56a9251 to e1820d7 Compare March 7, 2022 10:57
@terryjreedy
Copy link
Member

terryjreedy commented Mar 7, 2022

Judging from the commits pulled in, this PR branch was likely branched off of 3.10 or branch thereof. Please redo starting with 3.11 (main). Check the commit and diff list before hitting the green make-PR button. Also, is bpo not working to make a proper issue?

@terryjreedy terryjreedy closed this Mar 7, 2022
pmhahn pushed a commit to univention/univention-corporate-server that referenced this pull request Mar 7, 2022
Traceback (most recent call last):
  File "29_mail_related_modifications_of_user_objects", line 29, in check_login_lookup
    imap.log_in(mail, password)
  File "/usr/share/ucs-test/40_mail/essential/mailclient.py", line 54, in log_in
    self.login(usermail, password)
  File "/usr/lib/python3.7/imaplib.py", line 598, in login
    raise self.error(dat[-1])
imaplib.error: <exception str() failed>

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "29_mail_related_modifications_of_user_objects", line 274, in <module>
    main()
  File "29_mail_related_modifications_of_user_objects", line 93, in main
    check_login_lookup(host, usermail, password, False)
  File "29_mail_related_modifications_of_user_objects", line 37, in check_login_lookup
    if any([msg in str(ex) for msg in auth_errors]):
  File "29_mail_related_modifications_of_user_objects", line 37, in <listcomp>
    if any([msg in str(ex) for msg in auth_errors]):
BytesWarning: str() on a bytes instance
→ python/cpython#31722

Traceback (most recent call last):
  File "11mount-home", line 65, in <module>
    print(stdout, ret)
BytesWarning: str() on a bytes instance

Traceback (most recent call last):
  File "00check_forward_secrecy", line 88, in <module>
    check_pfs_cipher()
  File "00check_forward_secrecy", line 45, in check_pfs_cipher
    openssl_out = run_openssl().decode('UTF-8')
  File "00check_forward_secrecy", line 73, in run_openssl
    print("Openssl client STDOUT:\n", stdout)
BytesWarning: str() on a bytes instance

Traceback (most recent call last):
  File "47domain_user_lockout", line 185, in <module>
    check_error_present_in_output(stdout, stderr)
  File "47domain_user_lockout", line 147, in check_error_present_in_output
    if 'NT_STATUS_ACCOUNT_LOCKED_OUT' not in (stdout + stderr).decode('UTF-8'):
AttributeError: 'str' object has no attribute 'decode'
@spaceone
Copy link
Author

spaceone commented Mar 7, 2022

@terryjreedy The branch was already rebased onto main before you closed the MR. Can you reopen it again?

pmhahn pushed a commit to univention/univention-corporate-server that referenced this pull request Mar 7, 2022
Traceback (most recent call last):
  File "29_mail_related_modifications_of_user_objects", line 29, in check_login_lookup
    imap.log_in(mail, password)
  File "/usr/share/ucs-test/40_mail/essential/mailclient.py", line 54, in log_in
    self.login(usermail, password)
  File "/usr/lib/python3.7/imaplib.py", line 598, in login
    raise self.error(dat[-1])
imaplib.error: <exception str() failed>

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "29_mail_related_modifications_of_user_objects", line 274, in <module>
    main()
  File "29_mail_related_modifications_of_user_objects", line 93, in main
    check_login_lookup(host, usermail, password, False)
  File "29_mail_related_modifications_of_user_objects", line 37, in check_login_lookup
    if any([msg in str(ex) for msg in auth_errors]):
  File "29_mail_related_modifications_of_user_objects", line 37, in <listcomp>
    if any([msg in str(ex) for msg in auth_errors]):
BytesWarning: str() on a bytes instance
→ python/cpython#31722

Traceback (most recent call last):
  File "11mount-home", line 65, in <module>
    print(stdout, ret)
BytesWarning: str() on a bytes instance

Traceback (most recent call last):
  File "00check_forward_secrecy", line 88, in <module>
    check_pfs_cipher()
  File "00check_forward_secrecy", line 45, in check_pfs_cipher
    openssl_out = run_openssl().decode('UTF-8')
  File "00check_forward_secrecy", line 73, in run_openssl
    print("Openssl client STDOUT:\n", stdout)
BytesWarning: str() on a bytes instance

Traceback (most recent call last):
  File "47domain_user_lockout", line 185, in <module>
    check_error_present_in_output(stdout, stderr)
  File "47domain_user_lockout", line 147, in check_error_present_in_output
    if 'NT_STATUS_ACCOUNT_LOCKED_OUT' not in (stdout + stderr).decode('UTF-8'):
AttributeError: 'str' object has no attribute 'decode'
@spaceone spaceone changed the title bpo-XXXX: fix[imaplib]: call Exception with string instance bpo-46943: fix[imaplib]: call Exception with string instance Mar 7, 2022
@spaceone
Copy link
Author

spaceone commented Mar 7, 2022

Created upstream bug repport: https://bugs.python.org/issue46943

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

Successfully merging this pull request may close these issues.

4 participants