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
2024-04-24 20:04

满意答案

这里有一个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.

相关问答

更多

每周增加两次(Increase number twice a week)

这里有一个Javascript版本,你可以传递它应该开始计算的日期,你想要知道苹果的数量的日期,一周中的苹果将被添加,一天中的更新将发生以及将在每个日期添加的苹果数量。 Date.prototype.addDays = function (days) { var result = new Date(this); result.setDate(result.getDate() + days); return result; } Date.prototype.addHours ...

Excel公式将月份增加一个,每周增加一个月(Excel formula to increase month by one and week in month by one)

如下 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...

如何根据日期计算“周数”?(How is the “week number” calculated based on a date?)

这些数字是如何得出的? 那么,这取决于你使用的系统,但我怀疑你是在ISO-8601周数之后,这个定义如下: 2。10。10日历周号 根据一年中的第一个日历周是包括该年的第一个星期四以及日历年的最后一个日历周是紧接在该年之前的那一周的规则,在其日历年内标识日历周的序号。下一个日历年的第一个日历周 请记住,ISO-8601的一周开始于星期一,并在星期日结束 - 所以表达“第一个星期四”规则的另一种方式是,一年的第一周是包含新年至少四天的第一周。 另一个重要的一点是,当你使用“一周的一周”来表达价值时,...

从每周编号中选择MAX(Select MAX from each week number)

这将为您提供每周最大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...

每周记录总数(Total Number of Records per Week)

使用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 ...

SQL Server - 根据周数获取一周内的第一个日期?(SQL Server - Get first date in a week, given the week number?)

如果您以正确的方式考虑它, SO 1267126的答案可以应用于您的问题。 您在组中的每个错误报告日期都映射到同一周。 因此,根据定义,每个错误日期也必须映射到一周的同一个开始。 因此,您可以在错误报告日期运行“从给定日期开始的一周开始”计算,以及周数计算,并按两个(适度可怕)表达式进行分组,最后得到您寻求的答案。 SELECT DATEPART(wk, DATEADD(day, 0, DATEDIFF(d, 0, bg_reported_date))) [week], DATEAD...

NSDate来自周数(NSDate from week number)

您的问题有一个更简单的解决方案。 您可以使用NSCalendar的nextDateAfterDate()方法: let cal = NSCalendar.currentCalendar() let comps = NSDateComponents() comps.hour = 10 comps.weekday = cal.firstWeekday let now = NSDate() let fireDate = cal.nextDateAfterDate(now, matchingCompon...

如何计算下周的数量?(How Do I Calculate the Number of the Following Week?)

我面临着同样的问题。 我的解决方案 - 也许不是最好的解决方案,但它确实有效。 正如您已经提到的:大多数案例都是微不足道的,您只需知道年末/开始。 因此,我只需在下表中存储所需年数的相关周数: CREATE TABLE `NEXT_WEEK_TAB` ( `CUR_WEEK` varchar(8) NOT NULL, `NEXT_WEEK` varchar(8) NOT NULL, PRIMARY KEY (`CUR_WEEK`,`NEXT_WEEK`) ) 您现在使用当前算法获得...

相关文章

更多

solr faceted search

Faceted Search with Solr Posted byyonik Facet ...

[翻译][Trident] Trident state原理

原文地址:https://github.com/nathanmarz/storm/wiki/Tride ...

Riak Search

Basho: Riak Search Riak Search Introduction ...

storm client command

最近在研究实时日志分析,storm确实不错,以下是命令参数: storm help Syntax: ...

Faceted search

http://en.wikipedia.org/wiki/Faceted_search http:// ...

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

Custom SOLR Search Components - 2 Dev Tricks

I've been building some custom search components fo ...

Haystack - Search for Django

Haystack - Search for Django Search doesn' ...

Realtime Search: Solr vs Elasticsearch

Realtime Search: Solr vs Elasticsearch | Socialcast ...

Hadoop Namenode不能启动(dfs/name is in an inconsistent state)

前段时间自己的本机上搭的Hadoop环境(按文档的伪分布式),第一天还一切正常,后来发现每次重新开机以 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本