Reputation:
So, I've made a Flask server using Python on REPL and I'm trying to tell people how to use it. To do so, I'm making an example using Python. So far I have:
import requests
baseURL = "https://myurl.repl.co"
x = requests.get(baseURL)
print(x)
But what I get is:
<Response [200]>
Traceback (most recent call last): File "main.py", line 6, in <module> print(x[0]) TypeError: 'Response' object is not subscriptable
Does anyone know how to properly make a GET request to the server? Thanks!
Upvotes: 0
Views: 546
Reputation: 2663
import requests
baseURL = "https://myurl.repl.co"
x = requests.get(baseURL)
print(x.content)
Upvotes: 0
Reputation: 25
Install the requests module (much nicer than using urllib2) and then define a route which makes the necessary request - something like:
import requests
from flask import Flask
app = Flask(__name__)
@app.route('/some-url')
def get_data():
return requests.get('http://example.com').content
Depending on your set up though, it'd be better to configure your webserver to reverse proxy to the target site under a certain URL.
Upvotes: 0