Forums

Using PA to host an API. When I go directly to URL, I see the correct contents, but when I fetch()...

Hello, Using PA to host an API. When I go directly to URL, I see the correct contents, but when I fetch() from my react app, it fails.

I have been using the ChatGPT to help guide me this far, but it's not able to help me with this problem.

Could a kind human please point me in the right direction?

I'm sure it's something simple that I'm missing.

Any clues much appreciated!

Do you get any errors in the browser's developer console when the fetch fails?

hi

did u use a doc to setup your API to ChatGPT. It looks awfully complicated to send a simple message to I have a python flask sever that get messages from twilio.CHATGPT..

Do I have to use PIP3 to install some of CHATGPE?

How do I get a an api key to talk to Chatppt.

My flask server is patterened after ELIZA -- early AI program..

Thanks..

Melvyn Feuerman

We (as in, PythonAnywhere tech support) can only really help with PythonAnywhere-specific questions, but perhaps there are other people in the forums who can help with this more general programming question. Or maybe someone might be able to help on Stack Overflow?

I have an actual challenge with my API, it runs well on Pythonanywhere side, but the only challenge is when I am making requests to get response. I ended up using the default script to from Pythonanywhere to see if I will get the 'OK' status, but I failed also, please help.

I was trying to get response from a shared hosting server that I have python pip installed.

I can't seem to get even this default script running, please help with any suggestion.

`username = 'zett'
token = '************'

response = requests.get(
    'https://www.pythonanywhere.com/api/v0/user/{username}/cpu/'.format(
        username=username
    ),
    headers={'Authorization': 'Token {token}'.format(token=token)}
)
if response.status_code == 200:
    print('ALL IS OK!:')
else:
    print('Got unexpected status code {}: {!r}'.format(response.status_code, response.content))
       `

What is the actual output of the script?

That is the output that I get when I run to the browser

Original API is sitting here :

https://zett.pythonanywhere.com/

https://centraltenders.co.za/pythonscraperapp/error.png

Could you paste the output as text, as the images are not opening for me?

Ok, it looks like a server config error: it says:

'INTERNAL SERVER ERROR - The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application'.

  • A quick one, according to your knowledge, does the template code from PA that I pasted above supposed to work as it is?

If you maybe have any sample code that you close to guarantee that it works, please share it, I think many like me would also benefit.

https://zett.pythonanywhere.com/ that is the original json output from my API hosted at PA.

Ok, I have managed to host these error massage imgs: https://telepot.co.za/error_img.png The second one: error 500 second img

I appreciate your help.

The code you pasted should generally work as is if run as a script -- the only thing needing a fix is a missing line at the beginning: import requests. If you want to use that code in a web app, you would need to adapt the script (unfortunately the images are still not loading).