Last active
August 5, 2020 14:13
-
-
Save encukou/7d227abb62b50af5ed3539dfb725331d to your computer and use it in GitHub Desktop.
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
# To install/run/use, in a venv: | |
# | |
# $ python -m pip install flask flask-basicauth requests | |
# $ export FLASK_APP=quick-pypi-proxy.py | |
# $ export FLASK_DEBUG=1 | |
# $ flask run | |
# | |
# $ python -m pip install --index-url http://127.0.0.1:8089/simple notebook | |
# | |
# (If you're testing pip with --use-feature=fast-deps, turn it off.) | |
from flask import Flask, Response | |
from flask_basicauth import BasicAuth | |
import requests | |
app = Flask(__name__, static_url_path='/nopenopenope') | |
app.config['BASIC_AUTH_USERNAME'] = 'me' | |
app.config['BASIC_AUTH_PASSWORD'] = 'secret' | |
basic_auth = BasicAuth(app) | |
@app.route('/') | |
@app.route('/<path:path>') | |
@basic_auth.required | |
def mirror(path=''): | |
url = 'https://pypi.org/' + path | |
print(url) | |
response = requests.get(url) | |
return Response(response.content, response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment