def _send(self, filename): self.g.setup(multipart_post=self._update_params( { 'key': self.key, 'file': UploadFile(filename) }, self.send_config)) self._go(self._get_input_url(), 'Can not send captcha') return self._body('captcha_id')
def _send(self, filename): self.g.setup(multipart_post={ 'key': self.key, 'file': UploadFile(filename) }) self.g.go(self._get_input_url()) if self.g.response.code == 200: body = self.g.response.body.split('|') if len(body) == 2: self.captcha_id = int(body[1]) return self.captcha_id raise AntiGateError(body[0]) else: raise AntiGateError('%s %s' % (self.g.response.code, self.g.response.body))
def scraiping_add(): # Search link on the foto pointer = Grab() pointer.setup(timeout=25, connect_timeout=25) pointer.go('http://www.photosight.ru/photos/6599649/?from=best') response_url_foto = pointer.doc.select('//img[@id = "big_photo"]/@src').text() response_text_foto = pointer.doc.select('//img[@id = "big_photo"]/@alt').text() # Load foto on the PC urllib.request.urlretrieve(response_url_foto, 'image.png') # Load foto on the Server pointer.go('https://ourfoto.herokuapp.com/add_foto/') pointer.doc.set_input('image', UploadFile('image.png')) pointer.doc.set_input('text', response_text_foto) pointer.doc.submit() # Delete foto os.remove('image.png')
def test_upload_file(self): with temp_file() as file_path: g = self.prepare_form_grab() data = b'foo' with open(file_path, 'wb') as out: out.write(data) upload_data = UploadFile(file_path) g.doc.set_input('image', upload_data) g.doc.submit(make_request=False) post = dict(g.config['multipart_post']) self.assertTrue(isinstance(post['image'], UploadFile)) g.doc.submit() self.assertEqual(data, self.server.request['files']['image'][0]['body']) _, filename = os.path.split(file_path) self.assertEqual( filename, self.server.request['files']['image'][0]['filename']) self.assertEqual( 'application/octet-stream', self.server.request['files']['image'][0]['content_type'])
def test_upload_file_custom_filename(self): with temp_file() as file_path: g = self.prepare_form_grab() data = b'foo' with open(file_path, 'wb') as out: out.write(data) upload_data = UploadFile(file_path, filename='avatar.jpg') g.doc.set_input('image', upload_data) g.doc.submit(make_request=False) post = dict(g.config['multipart_post']) self.assertTrue(isinstance(post['image'], UploadFile)) g.doc.submit() self.assertEqual(data, self.server.request['files']['image'][0]['body']) self.assertEqual( 'avatar.jpg', self.server.request['files']['image'][0]['filename']) self.assertEqual( 'image/jpeg', self.server.request['files']['image'][0]['content_type'])
first_name = j['response'][0]['first_name'] last_name = j['response'][0]['last_name'] if (sex == 1): print "We have a girl!" print "http://vk.com/" + str(uid) + "(Name Here)" #Get ProfileUploadServer URL g.go( 'https://api.vk.com/method/photos.getProfileUploadServer.json?access_token=' + token) j = json.loads(g.response.body) #print ("Photo Upload URL: " + j['response']['upload_url']) #Multipart POST file g.setup(cookies={'remixsid': sid}, multipart_post={'photo': UploadFile(avatar)}) g.go(j['response']['upload_url']) j = json.loads(g.response.body) #SaveProfilePhoto g.go( 'https://api.vk.com/method/photos.saveProfilePhoto.json?hash=' + j['hash'] + '&photo=' + j['photo'] + '&server=' + str(j['server']) + '&access_token=' + token) j = json.loads(g.response.body) if (j['response']['saved'] == 1): print "Avatar uploaded!" GPIO.setup(BLUE, False) else: print "Avatar NOT changed"
def upload(filename): return UploadFile(filename)
def post_hw(g, filename): g.setup(url=HW_URL, multipart_post={"data[attachment]": UploadFile(filename) } ) g.request()