Forums

Host a Service on Pythonanywhere

Hello Pythonanywhere Staff,

im interested in upgrading my Account for the Web Dev Plan with 4 Web Apps. Though, Im still concerned about the following use case. I want to host two REST-APIs and two other Services that send requests to these REST APIs, aswell as send requests to external APIs, like for example Amazon.

I have noticed, that in the Free Plan it is not possible for a Service, to send requests to multiple APIs. Is this correct ?

And finally, are there any limitations concerning the above use case, except a high API load, which isnt the case.

Thanks in advance.

In a free plan, you can make requests to multiple APIs, so long as the APIs in question are on our allowlist -- and in general, any official public API can be added to that list.

However, with a paid account there are no restrictions on Internet access, so you can access APIs that aren't on the list.

Regarding the setup you describe -- that should work fine on PythonAnywhere :-)

Thank you for the reply. For my use case, I had a minor problem in the Free Plan. I was not able to connect to other services on Pythonanywhere. Is that intentionally forbidden ?

I had the following squid error: "ERROR The requested URL could not be retrieved"

I was using the requests module.

Is this restriction lifted in a paid plan ?

Thanks in advice.

In a free plan you certainly should be able to connect to other sites that are running inside PythonAnywhere. What is the code that you're using to make the connection, and what is the full error message?

The code I'm using is requests.get(http://somename.pythonanywhere.com/resource, header=HEADER, json=json_dict)

The Header and Json-Part is tested to be fully correct and there is definitely an endpoint designed for that URL, including GET as an allowed method. The error message thrown by the SQUID Proxy server is the following.

I have pasted the response html into a html-File and screenshoted the browser window.

Sorry I cant see the screenshot you provided. Could you try again to post it

Sure, here is the link:

https://imageupload.io/lIUqmf3GEs8IuXB

I have uploaded the image on a free image hosting website.

What do you see in your logs for that web app?

.

2023-10-18 21:11:39 #012<html><head>#012<meta type="copyright" content="Copyright (C) 1996-2019 The Squid Software Foundation and contributors">#012<meta http-equiv="Content-Type" content="text/html; charset=utf-8">#012<title>ERROR: The requested URL could not be retrieved</title>#012<style type="text/css"><!-- #012 /*#012 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors#012 *#012 * Squid software is distributed under GPLv2+ license and includes#012 * contributions from numerous individuals and organizations.#012 * Please see the COPYING and CONTRIBUTORS files for details.#012 */#012#012/*#012 Stylesheet for Squid Error pages#012 Adapted from design by Free CSS Templates#012 http://www.freecsstemplates.org#012 Released for free under a Creative Commons Attribution 2.5 License#012*/#012#012/* Page basics */#012* {#012#011font-family: verdana, sans-serif;#012}#012#012html body {#012#011margin: 0;#012#011padding: 0;#012#011background: #efefef;#012#011font-size: 12px;#012#011color: #1e1e1e;#012}#012#012/* Page displayed title area */#012#titles {#012#011ma

This is what I see in my logs, when sending the request. It is the result of printing response.text

Thanks in advance.

That is possible -- it doesn't look like any of default logging format (e.g. in server or access logs).

It is an entry from the server log. How is this possible ? What could be the problem. It doesnt seem to be a problem with the requests module.

Could you clarify what is the problem that you're trying to solve? Is the fact that it shows up in the server log, or rather the response.text doesn't show what you would expect?

The problem is, that Im getting a response from the Squid Server when Im trying to do a request to another Pythonanywhere App as stated before.

Therefore I'm not getting the response of the Pythonanywhere App I'm requesting to. This causes, that my hosted App is not working as it should and gets an internal server error, because I'm not able to parse the JSON, that is expected from the requesting App.

Thanks in advance.

PythonAnywhere sites are also protected by the allow list that is in place for free users. If the site has publicly available API documentation, you can request that it be added to the allow list: https://help.pythonanywhere.com/pages/RequestingAllowlistAdditions/