imaplib.select on big inbox: Too many arguments for command - python

I am trying to access to my emails in Gmail from a python script. The code I use is the following:
import imaplib
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login("username","password")
m.select("[Gmail]/All Mail")
When running this code in python 2, it works fine, I get the list of all my emails. In python 3 hoverer it fails with the error
>>> m.select("[Gmail]/All Mail")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.2/imaplib.py", line 674, in select
typ, dat = self._simple_command(name, mailbox)
File "/usr/lib/python3.2/imaplib.py", line 1121, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python3.2/imaplib.py", line 957, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: SELECT command error: BAD [b'[CLIENTBUG] Too many arguments for command']
I have done a bit of testing. It works fine on other folder such as "Inbox" where I get only 400 emails (vs 6000 in "All Mail").
Is it a problem related to the size of the list ? Why is it different in python 2 and 3 ?
Thank you

Try using m.select('"[Gmail]/All Mail"'), so that the double quotes get transmitted.
I suspect imaplib is not properly quoting the string, so the server gets what looks like two arguments: [Gmail]/All and Mail.

Related

ciscoaxl api python errors

I am starting out working on looking into using Python for some Cisco CUCM automation. I found the plugin ciscoaxl here, I installed it and programed the following script:
from ciscoaxl import axl
cucm = "10.10.20.1"
username = "axlusr"
password = "password1"
version = "12.5"
ucm = axl(username, password, cucm, version)
for phone in ucm.get_phones():
print(phone.name)
I am connected to Cisco's DevNET Sandbox and all the login and configuration for the AXL user appear to be correct, however I get the following output when I attempt to run the script:
Traceback (most recent call last):
File "%home%\AppData\Local\Programs\Python\Python39\axl-test.py", line 7, in <module>
for phone in ucm.get_phones():
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\ciscoaxl\axl.py", line 1877, in get_phones
for each in inner(skip):
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\ciscoaxl\axl.py", line 1869, in inner
res = self.client.listPhone(
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\proxy.py", line 40, in __call__
return self._proxy._binding.send(
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\wsdl\bindings\soap.py", line 130, in send
return self.process_reply(client, operation_obj, response)
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\wsdl\bindings\soap.py", line 195, in process_reply
return self.process_error(doc, operation)
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\wsdl\bindings\soap.py", line 283, in process_error
raise Fault(
zeep.exceptions.Fault: Unknown fault occured
I have run it on Windows10 in an IDLE enviornment, from the Linux-Subsystem (Ubuntu 20.04) via python and ipython3.
After some additional research this is a know issue with CUCM 12.5. It should be fixed in CU1 see here: https://github.com/mvantellingen/python-zeep/issues/989
I still receive this error on 12.5.1.12900-115, but I receive it when I don't have the appropriate permissions. Fixing user permissions for AXL access resolves it.

hubspot3 client and "too many retries" error

I'm trying to pull the details for a contact from hubspot using the recipient's email. I'm using the python3 client "hubspot3" (https://github.com/jpetrucciani/hubspot3).
Here's the code I'm submitting:
import requests
from hubspot3.contacts import ContactsClient
API_KEY=[myapikey]
client=ContactsClient(api_key=API_KEY,debug=True)
email='mytest#gmail.com'
client.get_contact_by_email(email)
The response:
WARNING:root:Too many retries for /contacts/v1/contact/email/nwnippy27+cb1#gmail.com/profile?hapikey=[myapikey]
Traceback (most recent call last):
File "hubspot_api_test.py", line 11, in <module>
client.get_contact_by_email(email)
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/contacts.py", line 38, in get_contact_by_email
"contact/email/{email}/profile".format(email=email), method="GET", **options
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/base.py", line 339, in _call
**options
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/base.py", line 245, in _call_raw
result = self._execute_request_raw(connection, request_info)
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/base.py", line 162, in _execute_request_raw
raise HubspotNotFound(result, request)
hubspot3.error.HubspotNotFound:
Hubspot Error
I'm reading this error as saying that the email address can't be found. Is that correct? If not, I appreciate any intel on the cause and solution.
OK ... so not super useful, but it turned out that this is just the error message you get when the email doesn't exist. After a few tries it gives up, which is why you get the "too many retries" error.

Python Dropbox API - Invalid "cursor" parameter

I've been migrating some Python 2.7.11 code to 3.5.1 after running into trouble with unicode. This was the last straw - since I started using the venv module there's no reason to be on 2.7 just because someone doesn't like 3!
The problem occurs while trying to run a one-way sync (ie. downloading changes only).
Here is the full error message, paths shortened:
Traceback (most recent call last):
File "%SCRIPT%.py", line 209, in <module>
updated_schedules = dbx_sync.One_Way_Sync(config['Dropbox Parameters']['Directory'], config['Dropbox Parameters']['Base Path'])
File "%COMMON_PATH%\modules\dropbox_sync_schedules.py", line 62, in One_Way_Sync
result = client.delta(cursor, base_path)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\client.py", line 569, in delta
return self.rest_client.POST(url, params, headers)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 322, in POST
return cls.IMPL.POST(*n, **kw)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 260, in POST
is_json_request=is_json_request)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 235, in request
raise ErrorResponse(r, r.read())
dropbox.rest.ErrorResponse: [400] 'Invalid "cursor" parameter: u"b\'\'"'
Searching for "invalid cursor parameter" wasn't any help, so I thought I'd come here.
u"b\'\'" is the key here. I just couldn't understand how that representation had ended up being sent as a string.
The issue was in reading the old cursor from a file (which for this example is empty): in Python 2 I had opened the file in mode rb - in Python 3 just r is all that's required, and everything works.
Hurrah!

Python pexpect.expect() on Telegram CLI

I'm trying to make a bot for Telegram on my RPi but I'm pretty new to this. I installed Telegram Cli and pexpect.
This is my test.py file:
import pexpect
telegram = pexpect.spawn('./telegram -k tg.pub')
telegram.expect("User")
telegram.send("msg Big_Boss test")
However this give me the following error:
Traceback (most recent call last):
File "test.py", line 5, in <module>
telegram.expect("User*")
File "/usr/local/lib/python2.7/dist-packages/pexpect/__init__.py", line 1451, in expect
timeout, searchwindowsize)
File "/usr/local/lib/python2.7/dist-packages/pexpect/__init__.py", line 1466, in expect_list
timeout, searchwindowsize)
File "/usr/local/lib/python2.7/dist-packages/pexpect/__init__.py", line 1554, in expect_loop
raise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Exception style platform.
I couldnt find any good documentation about the expect function. Basically what I am trying to do is send X when someone messages me something containing Y. But I can't get the first thing working. Simply sending a command.
Here's a Pexpect tutorial, and some sample code:
source
import pexpect
calc = pexpect.spawn('bc')
calc.expect("details")
print calc.send("1+2")
output
3

Creating a Draft message in Gmail using the imaplib in Python

I want to write a python module that sends data to a draft message in a G-mail account. I have written a script about two weeks ago that worked perfectly using imaplib. A simplified example of my module is below. (I have created a test email address for anyone to test this script on.)
import imaplib
import time
conn = imaplib.IMAP4_SSL('imap.gmail.com', port = 993)
conn.login('testpythoncreatedraft#gmail.com', '123456aaa')
conn.select('[Gmail]/Drafts')
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
It utilized the .append function, but today when I run the module and it produces the following error:
Traceback (most recent call last):
File "C:/Windows/System32/email_append_test.py", line 6, in <module>
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
File "C:\Python26\lib\imaplib.py", line 317, in append
return self._simple_command(name, mailbox, flags, date_time)
File "C:\Python26\lib\imaplib.py", line 1060, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "C:\Python26\lib\imaplib.py", line 895, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: APPEND command error: BAD ['Invalid Command']
As I said before, this module worked before. It successfully created draft messages with the string "Test" in its body. Since this script used to work, it seems more likely that it has something to do with a change Google made to the G-mail accounts IMAP features, but the error seems to indicate an error in the APPEND command. I have tested the python script on two different computer to see if my library file was corrupt, but the same error remained.
Also, I am using Python 2.6. Any help is appreciated.
Before the conn.append, add the following:
import email
Then change the conn.append line to read:
conn.append("[Gmail]/Drafts",
'',
imaplib.Time2Internaldate(time.time()),
str(email.message_from_string('TEST')))

Categories

Resources