I have done to implement a print pdf function. I use pyramid, wkhtmltopdf and jinja2 to generate pdf. It works fine in gunicorn. However, when I deploy it to production (I use circusd to run in production), the function fails without any error message. The source code is as follow:
pdf_renderer = PDFRenderer()
request = self.request
html = render('test.jinja2' , pdf_data, request)
response = request.response
response.write(pdf_renderer(html))
response.content_type = 'application/pdf'
response.headerlist.append(('Content-Disposition', 'attachment; filename='test.pdf'))
#Everything is ok except the final statement.
#circusd cannot run the statement "return response"
#However, gunicorn can do it
return response
So, do you have any suggestion or idea about my problem? It's so straight and I cannot understand why it works fine in gunicorn but fails in circusd
Try setting the content_length. It's possible the WSGI server you are using does not support streaming responses (which would happen if you are using .write() or .app_iter without setting a content_length). For your use-case, it's more likely that you'd be happy just setting the body which would take care of everything for you.
response.body = pdf_renderer(html)
Related
We are running into an issue that seems unique to AVPlayer. We've built a new architecture for our HLS streams which makes use of relative URLs. We can play these channels on a number of other players just fine, but when trying to build using AVPlayer, the channel gets 400 errors requesting either child manifests/segments with relative URLs.
Using curl, we are able to get a 200 success by getting to a url like: something.com/segmentfolder/../../abcd1234/videosegment_01.mp4
Curl is smart enough to get rid of the ../../ and create a valid path so the actual request (which can be seen using curl -v) looks something like: something.com/abcd1234/videosegment_01.mp4
Great. But AVPlayer doesn't do this. So it makes the request as is, which leads to a 400 error and it can't download the segment.
We were able to simulate this problem with Swift playground fairly easily with this code:
let hlsurl = URL(string: "website.com/segmentfolder/../../abc1234/videosegment.mp4")!
print(hlsurl)
print(hlsurl.standardized)
The first print shows the URL as is. Trying to GET that URL leads to a 400. The second print properly handles it by adding .standardized to the URL. This leads to a 200. The problem is, this only works for the top level/initial manifest, it doesn't work for all the child manifests and segments.
let url = URL(string: "website.com/segmentfolder/../../abc1234/videosegment.mp4")!
let task = URLSession.shared.dataTask(with: url.standardized) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
So question, does AVPlayer support relative URLs? If so, why can't it handle the ../../ in the URL path like other players and curl can? Is there a special way to get it to trigger standardizing ALL URL requests?
Any help would be appreciated.
I would like to send a POST request using the requests library in Python 3. The only difficulty I am having is in how to embed the urlencoded form part. The raw form looks like:
URLEncoded form:
data[type]: portion_send
data[attributes][style]: first_style
data[nodes][front][data][id]:1111
data[nodes][back][data][id]:1115
The best I have been able to do is to have:
data = {"data":{"attributes":{"style":"first_style"},"nodes":{"front":{"data":{"id":"1111"}},"back":{"data":{"id":"1115"}}},"type":"portion_send"}}
and to embed this inside a requests.post function with params = data, params = json.dumps(data), and data = json.dumps(data), each to no avail.
Does anyone have any ideas on how I can put this into a post request? The strange part is that the nesting jumps deeply and it is throwing me off. Thanks!
Python Requests Module
I need to know what the error message was to help you with the python requests module.
Using Linux or MacOS Curl`
If the above fails, you could try this:
os.execv('curl -d data=value http://YourWebsite.com')
It executes a separate process on your PC. If you run Windows, you could install curl from here: curl.haxx.se.
I have the following code returning 200, but the handle on Node REPL doesn't get returned
require('https').get('https://www.google.com/', (resp)=>{console.log(resp.statusCode)}).end();
It shows
200
But then it's waiting and doesn't return the handle until I press ENTER. Does this mean I have missed adding some directive?
I found the answer here. If the script is used as agent mode, the connection is kept-alive. A similar issue was posted here
node.js - after get request, script does not return to console
when I tried with agent:false- and provided host, port, path information as well - it worked properly.
Work code is sounds, but REPL (and callbacks) are toying with you...
It actually does return the "handle"... it's just looking like it is not in REPL.
"console.log(param)" return the string parameter (ie:200, in this case), at stdout(the console) WITH A RETURN LINE. Thus giving the illusion that you are between command lines... you are not... you could type the next command instead on pressing "ENTER", and it would work.
To demonstrate better, try running your code with separate lines, and try to type a command "before handle return".
const https = require('https');
var req = https.get('https://www.google.com/', (resp)=>{console.log(resp.statusCode)});
req.end();
I have written this small PoC for discord webhooks and i am getting error that Can not send empty string. I tried to google but couldn't find a documentation or an answer
here is my code
import requests
discord_webhook_url = 'https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxx/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
data = {'status': 'success'}
headers = {'Content-Type': 'application/json'}
res = requests.post(discord_webhook_url, data=data, headers=headers)
print(res.content)
I'm late, but I came across this issue recently, and seeing as it has not been answered yet, I thought I document my solution to the problem.
For the most part, it is largely due to the structure of the payload being wrong.
https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html provides an example of a working structure. https://discordapp.com/developers/docs/resources/channel#create-message is the official documentation.
I was also able to get a minimum test case working using: {"content": "Test"}.
If it still fails after that with the same error, the likely causes are:
If using curl, check to make sure there are no accidental escape / backslashes \
If using embeds with fields, ensure there are no empty values
When in doubt, ensure all values are populated, and not "". Through trial-and-error / the process of cancellation, you can figure out exactly what key-value pair is causing an issue, so I suggest playing with the webhook via curl before turning it into a full program.
I'm writing a Python 3 (3.5) script that will act as a simple command line interface to a user's stikked install. The API is pretty straight forward, and its documentation is available.
My post function is:
def submit_paste(paste):
global settings
data = {
'title': settings['title'],
'name': settings['author'],
'text': paste,
'lang': settings['language'],
'private': settings['private']
}
data = bytes(urllib.parse.urlencode(data).encode())
print(data)
handler = urllib.request.urlopen(settings['url'], data)
print(handler.read().decode('utf-8'))
When I run the script, I get the printed output of data, and the message returned from the API. The data encoding looks correct to me, and outputs:
b'private=0&text=hello%2C+world%0A&lang=text&title=Untitled&name=jacob'
As you can see, that contains the text= attribute, which is the only one actually required for the API call to successfully work. I've been able to successfully post to the API using curl as shown in that link.
The actual error produced by the API is:
Error: Missing paste text
Is the text attribute somehow being encoded incorrectly?
Turns out the problem wasn't with the post function, but with the URL. My virtual host automatically forwards http traffic to https. Apparently, Apache drops the post variables when it forwards.