Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import sys
- import os
- import urllib2
- import mimetypes
- import uuid
- class FormData:
- def __init__(self, boundary):
- self.boundary = boundary
- self.out = ''
- def add_text(self, name, text):
- self.out += '--%s\r\n' % self.boundary
- self.out += 'Content-Disposition: form-data; name="%s"\r\n\r\n' % name
- self.out += text + '\r\n'
- def add_file(self, name, filename):
- content = open(filename, 'rb').read()
- self.out += '--%s\r\n' % self.boundary
- self.out += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (name, os.path.basename(filename))
- extension = os.path.splitext(filename)[1]
- self.out += 'Content-Type: %s\r\n\r\n' % (mimetypes.types_map[extension] if extension in mimetypes.types_map else 'application/octet-stream')
- self.out += content + '\r\n'
- def __str__(self):
- return self.out + '--' + self.boundary + '--'
- subject = u'Привет'
- message = u'Иди нахуй'
- fd = FormData(uuid.uuid4().hex)
- fd.add_text('to', 'tz4678@gmail.com')
- fd.add_text('subject', subject.encode('utf-8'))
- fd.add_text('message', message.encode('utf-8'))
- fd.add_file('attachments[]', 'test.txt')
- req = urllib2.Request('http://x9a.ru/***.php', str(fd), {'Content-Type': 'multipart/form-data; boundary=' + fd.boundary});
- res = urllib2.urlopen(req)
- print res.read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement