Commit
·
c5da60b
1
Parent(s):
6d4e93b
Update main.py
Browse files
main.py
CHANGED
|
@@ -30,19 +30,18 @@ def latlon_to_pixel(loc):
|
|
| 30 |
@app.route('/proxy/<path:url>')
|
| 31 |
def proxy(url):
|
| 32 |
print('URL:', url)
|
|
|
|
| 33 |
try:
|
| 34 |
-
req = requests.get(f'http://{url}', stream=True, timeout=15)
|
| 35 |
content_type = req.headers['content-type']
|
| 36 |
-
|
| 37 |
-
if 'image' in content_type:
|
| 38 |
-
return send_file(req.raw, mimetype=content_type)
|
| 39 |
-
|
| 40 |
return Response(req.iter_content(chunk_size=10*1024), content_type=content_type)
|
| 41 |
|
| 42 |
except requests.exceptions.RequestException as e:
|
| 43 |
-
print('
|
| 44 |
return send_file('static/error.png', mimetype='image/png')
|
| 45 |
|
|
|
|
| 46 |
@app.route('/')
|
| 47 |
def index():
|
| 48 |
feed = random.randint(0, len(feed_dict) - 1)
|
|
|
|
| 30 |
@app.route('/proxy/<path:url>')
|
| 31 |
def proxy(url):
|
| 32 |
print('URL:', url)
|
| 33 |
+
headers = {'User-Agent': 'Mozilla/5.0'}
|
| 34 |
try:
|
| 35 |
+
req = requests.get(f'http://{url}', headers=headers, stream=True, timeout=15)
|
| 36 |
content_type = req.headers['content-type']
|
| 37 |
+
|
|
|
|
|
|
|
|
|
|
| 38 |
return Response(req.iter_content(chunk_size=10*1024), content_type=content_type)
|
| 39 |
|
| 40 |
except requests.exceptions.RequestException as e:
|
| 41 |
+
print(f'Error: {e}')
|
| 42 |
return send_file('static/error.png', mimetype='image/png')
|
| 43 |
|
| 44 |
+
|
| 45 |
@app.route('/')
|
| 46 |
def index():
|
| 47 |
feed = random.randint(0, len(feed_dict) - 1)
|