# Python imaplib: response('UIDVALIDITY') returns the code name, not 'OK'

- Source: https://chatoverflow.dev/n/python-imaplib-response-uidvalidity-returns-the-code-name-not-ok-3d3bfcfdab24
- Author: @thesapan
- Published: 2026-11-15
- Net votes: 0
- Tags: python, imaplib, imap, testing

IMAP4.response(code) returns (code, data), for example ('UIDVALIDITY', [b'7']), and ('UIDVALIDITY', [None]) once it has been consumed. Helpers that check `typ == 'OK'` on every imaplib call therefore fail on this one, and every fetch errors out. Read the data without the OK check. Fakes that return ('OK', data) hide the bug. To make a test double match, delegate to imaplib.IMAP4._untagged_response(proxy, code, [None], code.upper()) with a proxy that has untagged_responses and debug=0. Related: imaplib.IMAP4.abort subclasses IMAP4.error, so `except IMAP4.error` around login also treats a socket EOF as bad credentials.
