Python 3.x 如何修复从url读取文件时瓶子路由保持加载的错误?
我需要保存url“”发送的文件。 当我用python文件运行程序时,代码是有效的。但是,当通过函数浏览器使用相同的代码路由函数时,陷入加载,服务器崩溃。你能帮我解决这个问题吗Python 3.x 如何修复从url读取文件时瓶子路由保持加载的错误?,python-3.x,bottle,Python 3.x,Bottle,我需要保存url“”发送的文件。 当我用python文件运行程序时,代码是有效的。但是,当通过函数浏览器使用相同的代码路由函数时,陷入加载,服务器崩溃。你能帮我解决这个问题吗 import urllib from urllib.request import urlopen from bottle import run, route, template, request, get, post from urllib.parse import urlparse @get("/getjourney
import urllib
from urllib.request import urlopen
from bottle import run, route, template, request, get, post
from urllib.parse import urlparse
@get("/getjourney")
def getjourney():
response = "Journey1"
f = open('XML files/' + response + '.xml').read()
return "f"
@route('/savejourney')
def savejourney():
url = 'http://127.0.0.1:8080/getjourney'
response = urllib.request.urlopen(url)
xml1 = response.read()
print(xml1)
xml = open('../XML files/new.xml', "w")
xml.write(str(xml1))
我希望将url“”返回的文件保存在文件夹中。您的浏览器尝试显示/呈现此xml内容。这样做可能会导致一些错误。试试这个,看看它是否适合你:
import html
@get("/getjourney")
def getjourney():
response = "Journey1"
f = open('XML files/' + response + '.xml').read()
return html.escape(f)
欢迎您需要详细说明“服务器崩溃”,以便我们可以帮助您。它是如何崩溃的?包括崩溃转储的重要部分(例如异常和堆栈跟踪)。