Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python脚本自动下载gmail附件_Python_Python 3.x_Gmail Api - Fatal编程技术网

Python脚本自动下载gmail附件

Python脚本自动下载gmail附件,python,python-3.x,gmail-api,Python,Python 3.x,Gmail Api,我想要一个python脚本定期(像每小时一样)自动下载gmail附件,这是一种.jpg格式。我试过这段代码,但它不起作用 以上代码返回的是空白列表。即使我有带附件的邮件。 有人能帮我吗? 下面是整个存储库的URL。 尝试使用此链接:可能重复的尝试使用此链接:可能重复的 def get_csv_or_xl_attachments_from_msg_id(service, messageId): """returns a dict of all CSV attachments as pd.D

我想要一个python脚本定期(像每小时一样)自动下载gmail附件,这是一种.jpg格式。我试过这段代码,但它不起作用

以上代码返回的是空白列表。即使我有带附件的邮件。 有人能帮我吗? 下面是整个存储库的URL。

尝试使用此链接:可能重复的尝试使用此链接:可能重复的
def get_csv_or_xl_attachments_from_msg_id(service, messageId):
    """returns a dict of all CSV attachments as pd.DataFrames
    in the email associated with `messageId`. The keys for the
    dictionary are the csv filenames"""
    msg = service.messages().get(userId='me', id=messageId).execute()
    msg_parts = msg.get('payload').get('parts')
    headers = msg.get('payload').get('headers')
    subject = [h['value'] for h in headers if h['name']=='Subject'][0]
    if not msg_parts:
        return []
    msg_parts = _flatten_nested_email_parts(msg_parts)
    att_parts = [p for p in msg_parts if p['mimeType'] in [
            CSV_MIME_TYPE, XLSX_MIME_TYPE]]
    types = [mime_type_to_dtype(p['mimeType']) for p in att_parts]
    filenames = [p['filename'] for p in att_parts]
    datas = [_get_attachment_from_part(service, messageId, p) for p in att_parts]
    dfs = [_convert_attachment_data_to_dataframe(d, t)
            for d, t in zip(datas, types)]
    return [{'emailsubject': subject, 'filename': f, 'data': d}
            for f, d in zip(filenames, dfs)]


def query_for_csv_or_xl_attachments(service, search_query):
    message_ids = query_for_message_ids(service, search_query)
    csvs = [] 
    for msg_id in message_ids:
        loop_csvs = get_csv_or_xl_attachments_from_msg_id(service, msg_id)
        csvs.extend(loop_csvs)
    return csvs