import base64
name = base64.b64decode('---boundary_177909_1c62465c-ca94-430f-95cb-04824165d0cf\r\nContent-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: base64\r\n\r\nPCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBU\r\ncmFuc2l0aW9uYWwvL0VOIj4NCjxodG1sPg0KPGhlYWQ+DQo8bWV0YSBodHRw\r\nLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRlbnQ9InRleHQvaHRtbDsgY2hh\r\ncnNldD11dGYtOCI+DQo8dGl0bGU+UmVzZXJ2YXRpb24gQ29uZmlybWF0aW9u\r\nICMxODQxNDY8L3RpdGxlPg0KPHN0eWxlIHR5cGU9InRleHQvY3NzIj4NClRE\r\nIHsNCmZvbnQtc2l6ZToxMnB4Ow0KZm9udC1mYW1pbHk6IFZlcmRhbmEsIEFy\r\naWFsLCBUYWhvbWEsIEhlbHZldGljYTsNCmNvbG9yOiMwMDAwMDA7DQp9DQph\r\nDQp7DQoJdGV4dC1kZWNvcmF0aW9uOiB1bmRlcmxpbmU7DQoJY29sb3I6IDMz\r\nZ2UnIC8+DQo8dGFibGUgYm9yZGVyPSIwIiBjZWxscGFkZGluZz0iMyIgY2Vs\r\nbHNwYWNpbmc9IjAiIHN0eWxlPSJib3JkZXItY29sbGFwc2U6IGNvbGxhcHNl\r\nIiBMTUgMDAwMDAgbg0KMDAwMDAyMzQ0NCAwMDAwMCBuDQowMDAwMDQwMzU2IDAw\r\nMDAwIG4NCnRyYWlsZXINCjw8DQovUm9vdCAxIDAgUg0KL0luZm8gOCAwIFIN\r\nCi9TaXplIDIwDQo+Pg0KDQpzdGFydHhyZWYNCjUwMTc1DQolJUVPRg0K\r\n\r\n----boundary_177910_c457e629-613b-4137-8d93-cf90400beda1--\r\n\r\n----boundary_177909_1c62465c-ca94-430f-95cb-04824165d0cf--\r\n\r\n\r\n')
print name
从Python我正在阅读我的gmail并获得如上所述的编码信息。之后,我计划将其解码为普通HTML或普通文本。
如果我在代码上面运行,那么我会收到类似TypeError: Incorrect padding
的错误
不修改我的字符串(用()括起来)如何得到结果。
谢谢, 拉梅什。
答案 0 :(得分:0)
您不应该解码所获得的整个响应,因为它似乎包含发出的请求---boundary_177909_...
的边界。您需要解码的只是请求的主体。
import base64
print base64.b64decode("PCFET0NUWVB...Tc1DQolJUVPRg0K")