Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, url, target_file, progress):
threading.Thread.__init__(self)
self.target_file = target_file
self.progress = progress
self.curl = pycurl.Curl()
self.curl.setopt(pycurl.URL, url)
self.curl.setopt(pycurl.WRITEDATA, self.target_file)
self.curl.setopt(pycurl.FOLLOWLOCATION, 1)
self.curl.setopt(pycurl.NOPROGRESS, 0)
self.curl.setopt(pycurl.PROGRESSFUNCTION, self.progress)
self.curl.setopt(pycurl.MAXREDIRS, 5)
self.curl.setopt(pycurl.NOSIGNAL, 1)
post_dict['id']=omhe_dict['id']
post_dict['texti']=omhe_dict['texti']
print post_dict
for o in post_dict:
x=(str(o), str(post_dict[o]))
pf.append(x)
c = pycurl.Curl()
c.setopt(pycurl.URL, URL)
c.setopt(c.SSL_VERIFYPEER, False)
c.setopt(c.HTTPPOST, pf)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
c.setopt(pycurl.HTTPHEADER, ["Accept:"])
c.setopt(pycurl.USERPWD, user_and_pass)
c.perform()
return c
functools.partial(
self._curl_header_callback, headers, request.header_callback
),
)
if request.streaming_callback:
def write_function(b: Union[bytes, bytearray]) -> int:
assert request.streaming_callback is not None
self.io_loop.add_callback(request.streaming_callback, b)
return len(b)
else:
write_function = buffer.write
curl.setopt(pycurl.WRITEFUNCTION, write_function)
curl.setopt(pycurl.FOLLOWLOCATION, request.follow_redirects)
curl.setopt(pycurl.MAXREDIRS, request.max_redirects)
assert request.connect_timeout is not None
curl.setopt(pycurl.CONNECTTIMEOUT_MS, int(1000 * request.connect_timeout))
assert request.request_timeout is not None
curl.setopt(pycurl.TIMEOUT_MS, int(1000 * request.request_timeout))
if request.user_agent:
curl.setopt(pycurl.USERAGENT, native_str(request.user_agent))
else:
curl.setopt(pycurl.USERAGENT, "Mozilla/5.0 (compatible; pycurl)")
if request.network_interface:
curl.setopt(pycurl.INTERFACE, request.network_interface)
if request.decompress_response:
curl.setopt(pycurl.ENCODING, "gzip,deflate")
else:
curl.setopt(pycurl.ENCODING, None)
if request.proxy_host and request.proxy_port:
curl.setopt(pycurl.PROXY, request.proxy_host)
def _add_connection_configuration(self, easy_handle):
# TODO (jconnor 2013-01-22) make these configurable
easy_handle.setopt(pycurl.FOLLOWLOCATION, DEFAULT_FOLLOW_LOCATION)
easy_handle.setopt(pycurl.MAXREDIRS, DEFAULT_MAX_REDIRECTS)
easy_handle.setopt(pycurl.CONNECTTIMEOUT, DEFAULT_CONNECT_TIMEOUT)
easy_handle.setopt(pycurl.TIMEOUT, DEFAULT_REQUEST_TIMEOUT)
easy_handle.setopt(pycurl.NOPROGRESS, DEFAULT_NO_PROGRESS)
def handle_request(self):
curl_handle = pycurl.Curl()
# set default options.
curl_handle.setopt(pycurl.URL, self.request_url)
curl_handle.setopt(pycurl.REFERER, self.request_url)
curl_handle.setopt(pycurl.USERAGENT, self.useragent)
curl_handle.setopt(pycurl.TIMEOUT, 5184000)
curl_handle.setopt(pycurl.CONNECTTIMEOUT, 120)
curl_handle.setopt(pycurl.HEADER, True)
curl_handle.setopt(pycurl.VERBOSE, 1)
curl_handle.setopt(pycurl.FOLLOWLOCATION, 1)
curl_handle.setopt(pycurl.MAXREDIRS, 5)
if(self.request_headers and len(self.request_headers) > 0):
tmplist = list()
for(key, value) in self.request_headers.items():
tmplist.append(key + ':' + value)
curl_handle.setopt(pycurl.HTTPHEADER, tmplist)
#if(self.method == self.HTTP_PUT):
#目前只需支持POST
curl_handle.setopt(pycurl.HTTPPROXYTUNNEL, 1)
curl_handle.setopt(pycurl.POSTFIELDS, self.request_body)
response = StringIO.StringIO()
curl_handle.setopt(pycurl.WRITEFUNCTION, response.write)
curl_handle.perform()
self.response_code = curl_handle.getinfo(curl_handle.HTTP_CODE)
header_size = curl_handle.getinfo(curl_handle.HEADER_SIZE)
if post:
curl.setopt(pycurl.POST, 1)
if params:
if post:
curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(params))
else:
url = "?".join((url, urllib.urlencode(params)))
curl.setopt(pycurl.URL, str(url))
if username and password:
curl.setopt(pycurl.USERPWD, "%s:%s" % (str(username), str(password)))
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.TIMEOUT, 15)
curl.setopt(pycurl.CONNECTTIMEOUT, 8)
curl.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_1_0)
content = StringIO.StringIO()
hdr = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, content.write)
curl.setopt(pycurl.HEADERFUNCTION, hdr.write)
print curl, url, header
try:
curl.perform()
except pycurl.error, e:
raise e
http_code = curl.getinfo(pycurl.HTTP_CODE)
else:
resolve = ''
if proxy_type in PROXY_TYPE_MAP:
proxy_type = PROXY_TYPE_MAP[proxy_type]
else:
raise ValueError('Invalid proxy_type %r' % proxy_type)
fp = pycurl.Curl()
fp.setopt(pycurl.SSL_VERIFYPEER, 0)
fp.setopt(pycurl.SSL_VERIFYHOST, 0)
fp.setopt(pycurl.HEADER, 1)
fp.setopt(pycurl.USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0')
fp.setopt(pycurl.NOSIGNAL, 1)
fp.setopt(pycurl.FOLLOWLOCATION, int(follow))
fp.setopt(pycurl.MAXREDIRS, int(max_follow))
fp.setopt(pycurl.CONNECTTIMEOUT, int(timeout_tcp))
fp.setopt(pycurl.TIMEOUT, int(timeout))
fp.setopt(pycurl.PROXY, proxy)
fp.setopt(pycurl.PROXYTYPE, proxy_type)
fp.setopt(pycurl.RESOLVE, [resolve])
headers_output, body_output = StringIO(), StringIO()
fp.setopt(pycurl.HEADERFUNCTION, headers_output.write)
fp.setopt(pycurl.HEADER, 0)
fp.setopt(pycurl.WRITEFUNCTION, body_output.write)
def debug_func(t, s):
if max_mem > 0 and request.tell() > max_mem:
return 0
if t in (pycurl.INFOTYPE_HEADER_OUT, pycurl.INFOTYPE_DATA_OUT):
request.write(s)
for b in rsp.photos[0].photo:
print('In b')
if b!=None:
counter = counter + 1
##print(http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg)
myurl = 'http://farm'+b['farm']+".static.flickr.com/"+b['server']+"/"+b['id']+"_"+b['secret']+'.jpg'
fname = outpath+pos_queries[current_tag]+str(counter)+'.jpg' #b['id']+"_"+b['secret']+'.jpg'
print(myurl)
print(fname)
mycurl = pycurl.Curl()
mycurl.setopt(pycurl.URL, str(myurl))
myfile = open(fname,"wb")
mycurl.setopt(pycurl.WRITEDATA, myfile)
mycurl.setopt(pycurl.FOLLOWLOCATION, 1)
mycurl.setopt(pycurl.MAXREDIRS, 5)
mycurl.setopt(pycurl.NOSIGNAL, 1)
mycurl.perform()
mycurl.close()
myfile.close()
out_file.write('URL: '+myurl+'\n')
out_file.write('File: '+ fname+'\n')
out_file.write('photo: ' + b['id'] + ' ' + b['secret'] + ' ' + b['server'] + '\n')
out_file.write('owner: ' + b['owner'] + '\n')
out_file.write('title: ' + b['title'].encode("ascii","replace") + '\n')
out_file.write('originalsecret: ' + b['originalsecret'] + '\n')
out_file.write('originalformat: ' + b['originalformat'] + '\n')
out_file.write('o_height: ' + b['o_height'] + '\n')
out_file.write('o_width: ' + b['o_width'] + '\n')
out_file.write('datetaken: ' + b['datetaken'].encode("ascii","replace") + '\n')
out_file.write('dateupload: ' + b['dateupload'].encode("ascii","replace") + '\n')
post_dict['id']=omhe_dict['id']
post_dict['texti']=omhe_dict['texti']
print post_dict
for o in post_dict:
x=(str(o), str(post_dict[o]))
pf.append(x)
c = pycurl.Curl()
c.setopt(c.SSL_VERIFYPEER, False)
c.setopt(pycurl.URL, URL)
c.setopt(c.HTTPPOST, pf)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
c.setopt(pycurl.HTTPHEADER, ["Accept:"])
c.setopt(pycurl.USERPWD, user_and_pass)
c.perform()
return c