Last active
February 14, 2018 14:03
-
-
Save kuyagic/1093edb0d73252fedacaaa626665694a to your computer and use it in GitHub Desktop.
upload image to sougou
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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