Http request in server script

hi

is it possible to make http request in server script?
if possible then how?

thanks

frappe.make_get_request

Make a GET request.

Example: frappe.make_get_request('https://example.com')

frappe.make_post_request

Make a POST request.

Example: frappe.make_post_request('https://example.com', data={'username: 'test'})

you can refer the documentation
https://frappeframework.com/docs/v14/user/en/desk/scripting/script-api

1 Like

thank you

Aya, have you learned how to get the response from the http request using frappe methods(make_get_request or make_post_request)?

but what if the response is not a valid JSON object? frappe.make_get_request() expects that…

I have the problem that the Github API only returns RAW for files larger than 1MB and not as content within the JSON object. Does anyone have an idea how to get the server script to make the Python package requests directly usable?

I don’t know if I understood right, but try converting the response to Python Dictionary, using json.loads() inside your Server Script, it worked for me.

my problem was in file frappe/frappe/integrations/utils.py line 25ff. I had “+json” in my content-type because the “+json” is mentioned in the github api description. But it also returns RAW data if “+json” is missing in ‘application/vnd.github.raw’.

The frappe function make_request was trying to parse to json, but it will work with non json data. But this is now working.

Unfortunately, the content of the PDF file that I receive from the API is destroyed during the conversion from response.content to response.text and is no longer a valid PDF file because something is wrong with the encoding to UTF-8.


Source(requests/src/requests/models.py at main · psf/requests · GitHub Line 910ff)

Python requests decodes the content with option “ignore”, which means that the resulting text is with questionmarks and the original information is gone forever.

It would be nice to access response.content and not only response.text :frowning: