按名称值读取原始http请求

时间:2018-02-14 11:35:59

标签: python httprequest

鉴于以下数据,我正在尝试按名称获取每个内容处置的值。例如,获取主题或值。例如,我希望能够找到“html”,它会给我:

  

<html><body><strong>Hello SendGrid!</body></html>

我不知道该怎么做?有这样的想法:

  

subject = full_msg [full_msg.find('Content-Disposition:form-data;   name =“subject”')+ len('Content-Disposition:form-data;   NAME = “受试者” '):full_msg.rfind(' - XYZZY')]条()

--xYzZY
Content-Disposition: form-data; name="headers"

MIME-Version: 1.0
Received: by 0.0.0.0 with HTTP; Wed, 10 Aug 2016 18:10:13 -0700 (PDT)
From: Example User <test@example.com>
Date: Wed, 10 Aug 2016 18:10:13 -0700
Subject: Inbound Parse Test Data
To: inbound@inbound.example.com
Content-Type: multipart/alternative; boundary=001a113df448cad2d00539c16e89

--xYzZY
Content-Disposition: form-data; name="dkim"

{@sendgrid.com : pass}
--xYzZY
Content-Disposition: form-data; name="to"

inbound@inbound.example.com
--xYzZY
Content-Disposition: form-data; name="html"

<html><body><strong>Hello SendGrid!</body></html>

--xYzZY
Content-Disposition: form-data; name="from"

Example User <test@example.com>
--xYzZY
Content-Disposition: form-data; name="text"

Hello SendGrid!

--xYzZY
Content-Disposition: form-data; name="sender_ip"

0.0.0.0
--xYzZY
Content-Disposition: form-data; name="envelope"

{"to":["inbound@inbound.example.com"],"from":"test@example.com"}
--xYzZY
Content-Disposition: form-data; name="attachments"

0
--xYzZY
Content-Disposition: form-data; name="subject"

Testing non-raw
--xYzZY
Content-Disposition: form-data; name="charsets"

{"to":"UTF-8","html":"UTF-8","subject":"UTF-8","from":"UTF-8","text":"UTF-8"}
--xYzZY
Content-Disposition: form-data; name="SPF"

pass
--xYzZY--

1 个答案:

答案 0 :(得分:0)

import email

full_msg = request.POST['email']
msg = email.message_from_string(full_msg)
from_address = msg["from"]