I'm trying to add CSS to the HTML that my python code generates. This line causes an error when I post the HTML:
html += '<link rel=\'stylesheet\' href=\'{{ url_for(\'static\', filename=\'css/main.css\') }}\'>'
I also tried putting the quotes on the outside, I get the same error:
html += "<link rel=\'stylesheet\' href=\'{{ url_for(\'static\', filename=\'css/main.css\') }}\'>"
The error I'm getting is:
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:
if I remove that one line I can PUT to the web page.
This is the code that writes the HTML to the page:
def write_data_to_confluence(auth, html, pageid, title = None):
info = get_page_info(auth, pageid)
ver = int(info['version']['number']) + 1
ancestors = get_page_ancestors(auth, pageid)
anc = ancestors[-1]
del anc['_links']
del anc['_expandable']
del anc['extensions']
if title is not None:
info['title'] = title
data = {
'id' : str(pageid),
'type' : 'page',
'title' : info['title'],
'version' : {'number' : ver},
'ancestors' : [anc],
'body' : {
'storage' :
{
'representation' : 'storage',
'value' : str(html)
}
}
}
data = json.dumps(data)
url = '{base}/{pageid}'.format(base = BASE_URL, pageid = pageid)
r = requests.put(
url,
data = data,
auth = auth,
headers = { 'Content-Type' : 'application/json' }
)
r.raise_for_status()
print("Wrote '%s' version %d" % (info['title'], ver))
print("URL: %s%d" % (VIEW_URL, pageid))
I think I am quoting it wrong. I tried a couple different ways, but have yet to get it right. How can I quote this correctly?
html += "..."so you don't have to escape all the single quotes inside the string. That should make it easier to see the real error.html += """<link rel='stylesheet' href="{{ url_for('static', filename='css/main.css') }}">"""raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://wiki.us.cworld.company.com/rest/api/content/138335201url_for()depends on flask being installed. I will try installing that and see if I can get this to work!