imaplib.error:命令SEARCH在状态AUTH中非法,只允许在SELECTED状态(imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED)
def connect_imap(): m = imaplib.IMAP4_SSL("imap.gmail.com", 993) print("{0} Connecting to mailbox via IMAP...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"))) details = login_credentials() m.login(details[0], details[1]) return m m = connect_imap() typ, data = m.search(None, 'ALL') m.close() m.logout()
上面代码的输出是:
2016-08-24 10:55:34 Connecting to mailbox via IMAP... Traceback (most recent call last): File "/home/zoikmail/Desktop/test.py", line 25, in <module> typ, data = m.search(None, 'ALL') File "/usr/lib/python2.7/imaplib.py", line 640, in search typ, dat = self._simple_command(name, *criteria) File "/usr/lib/python2.7/imaplib.py", line 1088, in _simple_command return self._command_complete(name, self._command(name, *args)) File "/usr/lib/python2.7/imaplib.py", line 838, in _command ', '.join(Commands[name]))) imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED [Finished in 1.2s with exit code 1] [shell_cmd: python -u "/home/zoikmail/Desktop/test.py"] [dir: /home/zoikmail/Desktop] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
上面的代码有什么问题?
def connect_imap(): m = imaplib.IMAP4_SSL("imap.gmail.com", 993) print("{0} Connecting to mailbox via IMAP...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"))) details = login_credentials() m.login(details[0], details[1]) return m m = connect_imap() typ, data = m.search(None, 'ALL') m.close() m.logout()
The Output of the above code is:
2016-08-24 10:55:34 Connecting to mailbox via IMAP... Traceback (most recent call last): File "/home/zoikmail/Desktop/test.py", line 25, in <module> typ, data = m.search(None, 'ALL') File "/usr/lib/python2.7/imaplib.py", line 640, in search typ, dat = self._simple_command(name, *criteria) File "/usr/lib/python2.7/imaplib.py", line 1088, in _simple_command return self._command_complete(name, self._command(name, *args)) File "/usr/lib/python2.7/imaplib.py", line 838, in _command ', '.join(Commands[name]))) imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED [Finished in 1.2s with exit code 1] [shell_cmd: python -u "/home/zoikmail/Desktop/test.py"] [dir: /home/zoikmail/Desktop] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
What's wrong in the above code?
原文:https://stackoverflow.com/questions/39115141
最满意答案
这里有一个Javascript版本,你可以传递它应该开始计算的日期,你想要知道苹果的数量的日期,一周中的苹果将被添加,一天中的更新将发生以及将在每个日期添加的苹果数量。
Date.prototype.addDays = function (days) { var result = new Date(this); result.setDate(result.getDate() + days); return result; } Date.prototype.addHours = function (hours) { var result = new Date(this); result.setHours(result.getHours() + hours); return result; } function getApples(startdate, date, updateDays, updateTime, applesPerUpdate) { var startDay = startdate.getDay(); var firstUpdateDate; for(day of updateDays) { if (day >= startDay) {//assumes startdate has no time added firstUpdateDate = startdate.addDays(day - startDay).addHours(updateTime); break; } } if (!firstUpdateDate) firstUpdateDate = startdate.addDays(7 - (startDay - updateDays[0])).addHours(updateTime); var updateDaysReverse = updateDays.slice(0).reverse();//clones the array var dateDay = date.getDay(); var lastUpdateDate; for(day of updateDaysReverse) { if (day < dateDay || day == dateDay && date.getHours() > updateTime) { lastUpdateDate = date.addDays(day - dateDay); break; } } if (!lastUpdateDate) lastUpdateDate = date.addDays(updateDaysReverse[0] - (7 + dateDay)); lastUpdateDate = new Date(Date.UTC(1900 + lastUpdateDate.getYear(), lastUpdateDate.getMonth(), lastUpdateDate.getDate(), updateTime, 0, 0, 0)); var secs = Math.trunc((lastUpdateDate - firstUpdateDate)); if (secs < 0) return 0; var dayDiffs = []; for(day of updateDays) dayDiffs.push(day - updateDays[0]); var weeks = Math.trunc(secs / 604800000); var days = Math.trunc((secs % 604800000) / 86400000); var apples = weeks * updateDays.length; for(diff of dayDiffs) { if (diff <= days) apples++; else break; } return apples * applesPerUpdate; } // important, day and month is zero-based var startDate = new Date(Date.UTC(2016, 01, 07, 0, 0, 0, 0)); var updateDays = [2, 4];// 0 = sunday , have to be in order and must be 0 <= x < 7 var updateTime = 9; console.log(getApples(startDate, new Date(), updateDays, updateTime, 2));
比我更复杂,我没有多少测试,所以可能有错误。
这是一个玩弄价值观的人。
Here a Javascript version, you can pass it the date it should start counting, the date you want to know the ammount of apples of, the days of the week apples will be added, the hours of the day the updat will take place and the ammount of apples that will be added on each of these dates.
Date.prototype.addDays = function (days) { var result = new Date(this); result.setDate(result.getDate() + days); return result; } Date.prototype.addHours = function (hours) { var result = new Date(this); result.setHours(result.getHours() + hours); return result; } function getApples(startdate, date, updateDays, updateTime, applesPerUpdate) { var startDay = startdate.getDay(); var firstUpdateDate; for(day of updateDays) { if (day >= startDay) {//assumes startdate has no time added firstUpdateDate = startdate.addDays(day - startDay).addHours(updateTime); break; } } if (!firstUpdateDate) firstUpdateDate = startdate.addDays(7 - (startDay - updateDays[0])).addHours(updateTime); var updateDaysReverse = updateDays.slice(0).reverse();//clones the array var dateDay = date.getDay(); var lastUpdateDate; for(day of updateDaysReverse) { if (day < dateDay || day == dateDay && date.getHours() > updateTime) { lastUpdateDate = date.addDays(day - dateDay); break; } } if (!lastUpdateDate) lastUpdateDate = date.addDays(updateDaysReverse[0] - (7 + dateDay)); lastUpdateDate = new Date(Date.UTC(1900 + lastUpdateDate.getYear(), lastUpdateDate.getMonth(), lastUpdateDate.getDate(), updateTime, 0, 0, 0)); var secs = Math.trunc((lastUpdateDate - firstUpdateDate)); if (secs < 0) return 0; var dayDiffs = []; for(day of updateDays) dayDiffs.push(day - updateDays[0]); var weeks = Math.trunc(secs / 604800000); var days = Math.trunc((secs % 604800000) / 86400000); var apples = weeks * updateDays.length; for(diff of dayDiffs) { if (diff <= days) apples++; else break; } return apples * applesPerUpdate; } // important, day and month is zero-based var startDate = new Date(Date.UTC(2016, 01, 07, 0, 0, 0, 0)); var updateDays = [2, 4];// 0 = sunday , have to be in order and must be 0 <= x < 7 var updateTime = 9; console.log(getApples(startDate, new Date(), updateDays, updateTime, 2));
Was more coplicated than I thaught, and i havn't testet it much, so there may be bugs.
Here is a plunker to play with the values.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
每周增加两次(Increase number twice a week)[2021-08-31]
这里有一个Javascript版本,你可以传递它应该开始计算的日期,你想要知道苹果的数量的日期,一周中的苹果将被添加,一天中的更新将发生以及将在每个日期添加的苹果数量。 Date.prototype.addDays = function (days) { var result = new Date(this); result.setDate(result.getDate() + days); return result; } Date.prototype.addHours = fun ... -
如下 month date_of_first_Monday how_many_Mondays Ith_Monday_request the_date_request 1/1 =Choose(Weekday(A2,2),0,6,5,4,3,2,1)+A2 =roundup((day(eomonth(a2,0 ...
-
这些数字是如何得出的? 那么,这取决于你使用的系统,但我怀疑你是在ISO-8601周数之后,这个定义如下: 2。10。10日历周号 根据一年中的第一个日历周是包括该年的第一个星期四以及日历年的最后一个日历周是紧接在该年之前的那一周的规则,在其日历年内标识日历周的序号。下一个日历年的第一个日历周 请记住,ISO-8601的一周开始于星期一,并在星期日结束 - 所以表达“第一个星期四”规则的另一种方式是,一年的第一周是包含新年至少四天的第一周。 另一个重要的一点是,当你使用“一周的一周”来表达价值时,你需要使用 ...
-
从每周编号中选择MAX(Select MAX from each week number)[2023-07-12]
这将为您提供每周最大gameID所有周。 返回的行将以weekNum的形式按升序排序。 SELECT weekNum, MAX(gameID) AS lastGameOfWeek FROM nflp_schedule GROUP BY weekNum ORDER BY weekNum ASC 要根据上面派生的返回的gameID获取其他值,您需要执行subselect作为过滤条件或连接。 这看起来像这样(使用subselect): SELECT gameID, weekNum, homeScore, vis ... -
每周记录总数(Total Number of Records per Week)[2023-08-31]
使用cross join应该可以工作,我只是要粘贴下面的SQL Fiddle的markdown输出。 对于2013-01-08系列来说,你的样本输出似乎不正确:thisyr应该是2,而不是3.这可能不是最好的方法,但是我的Postgresql知识还有很多不足之处。 SQL小提琴 PostgreSQL 9.2.4架构设置 : CREATE TABLE Table1 ("Pt_ID" varchar(6), "exam_date" date); INSERT INTO Table1 ("Pt_ ... -
SQL Server - 根据周数获取一周内的第一个日期?(SQL Server - Get first date in a week, given the week number?)[2022-12-03]
如果您以正确的方式考虑它, SO 1267126的答案可以应用于您的问题。 您在组中的每个错误报告日期都映射到同一周。 因此,根据定义,每个错误日期也必须映射到一周的同一个开始。 因此,您可以在错误报告日期运行“从给定日期开始的一周开始”计算,以及周数计算,并按两个(适度可怕)表达式进行分组,最后得到您寻求的答案。 SELECT DATEPART(wk, DATEADD(day, 0, DATEDIFF(d, 0, bg_reported_date))) [week], DATEADD(dd, ... -
NSDate来自周数(NSDate from week number)[2022-09-14]
您的问题有一个更简单的解决方案。 您可以使用NSCalendar的nextDateAfterDate()方法: let cal = NSCalendar.currentCalendar() let comps = NSDateComponents() comps.hour = 10 comps.weekday = cal.firstWeekday let now = NSDate() let fireDate = cal.nextDateAfterDate(now, matchingComponents: ... -
我面临着同样的问题。 我的解决方案 - 也许不是最好的解决方案,但它确实有效。 正如您已经提到的:大多数案例都是微不足道的,您只需知道年末/开始。 因此,我只需在下表中存储所需年数的相关周数: CREATE TABLE `NEXT_WEEK_TAB` ( `CUR_WEEK` varchar(8) NOT NULL, `NEXT_WEEK` varchar(8) NOT NULL, PRIMARY KEY (`CUR_WEEK`,`NEXT_WEEK`) ) 您现在使用当前算法获得以下一周: ...