Skip to content

Instantly share code, notes, and snippets.

@kuyagic
Last active February 14, 2018 14:03
Show Gist options
  • Save kuyagic/1093edb0d73252fedacaaa626665694a to your computer and use it in GitHub Desktop.
Save kuyagic/1093edb0d73252fedacaaa626665694a to your computer and use it in GitHub Desktop.
upload image to sougou
import requests
import time
import bs4
from urllib.parse import urlparse, unquote
from flask import Blueprint, request, make_response, Response, send_file, redirect, stream_with_context, jsonify
@bp.route('/sougou/upload', methods=['POST'])
def upload_to_sougou():
if 'image' not in request.files:
return jsonify({
'code': 400
, 'ret': request.form.get('ret', '0')
, 'msg': 'no image provided'})
f = request.files['image']
url = 'http://pic.sogou.com/ris_upload'
h = {
'DNT': '1',
'Origin': 'http://pic.sogou.com',
'Referer': 'http://pic.sogou.com/'
}
# f = open('d:/1.jpg', 'rb')
fn = '%s.jpg' % str(int(time.time()))
dt = {
'flag': '1',
'filename': fn,
# 'pic_path': (fn, f, 'application/octet-stream')
}
fl = {'pic_path': (fn, f, 'application/octet-stream')}
r = requests.post(url, headers=h, data=dt, files=fl)
query = str(urlparse(r.url).query)
first = query.split('&')[0]
fnl_url = first.split('=')[1]
result = unquote(fnl_url).replace('http://', 'https://')
return_value = {
'code': 0
, 'url': result
}
return jsonify(return_value)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment