I am trying to search for messages in the Sent (actually i care for both) but I only get incoming messages. For the time being i have
imap_conn.select()
str_
Man, the error message is so misleading. What it's really saying is that you have tried to select an invalid folder name hence the search operation fails.
To verify/check the current valid folders/labels do something like:
Using ImapClient
from imapclient import IMAPClient
## Connect, login and select the INBOX
imap_conn = IMAPClient('imap.gmail.com', use_uid=True, ssl=ssl)
imap_conn.login(USERNAME, PASSWORD)
print(imap_conn.list_folders())
Using imaplib
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('myusername@gmail.com', 'mypassword')
print(mail.list())
After I could see what folder names it was expecting, all was well.