Reputation: 31
I am new to bottle. I have searched for the answer but could not get any.
Is there anyway to load a page without redirect
?
The code is like this:
from bottle import get, run, template
@get('/list/item')
def listItems():
r = requests.get('my/url/which/works/')
return r.content
if __name__ == '__main__':
run(host='localhost', port=8080 )
and the webpage is empty. I have also tried return r.text
, return template(r.content)
, return str(r.content)
, return str(r.content.decode('utf-8'))
, and
nf = urllib.urlopen('my/url/whick/works')
return nf.read()
none of them returns the page I want.
However, if I write this return r.content[0]
, it works. the page will show the first letter, which is '<'. But if I write return r.content[0:100]
, it returns a empty page again.
If I run the requests in command line, this is what it returns:
>>> import requests
>>> r = requests.get('my/url/which/works/')
>>>
>>> r.content
'<?xml version="1.0" encoding="utf-8" ?> \n<body copyright="...>\n</body>\n'
Is that possible that anyone can help about this? Thank you very much.
Upvotes: 0
Views: 68
Reputation: 18127
Your question doesn't specify what you expect to see when your code works as expected, but this may help you:
from bottle import get, run, template, response
@get('/list/item')
def listItems():
r = requests.get('my/url/which/works/')
response.content_type = 'text/plain' # added this
return r.content
...
The only change is that your webserver will now be setting the content type of the response to text/plain
, which should make your browser render the page.
Longer term, if (as I'm inferring from your question) you intend to return XML responses, then I suggest either installing a browser plugin (here's an example), or, better yet, use curl
or wget
to see the precise response. This will help you debug your server's responses.
Upvotes: 1