Python requests 503 erros when trying to access localhost:8000

后端 未结 2 656
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 05:25

I am facing a bit of a situation,

Scenario: I got a django rest api running on my localhost:8000 and I want to access the api using my command line. I have tried urllib

相关标签:
2条回答
  • 2021-01-28 05:32

    If you are registering your serializers with DefaultRouter then your api will appear at

    http://localhost:8000/api/ for an html view of the index
    http://localhost:8000/api/.json for a JSON view of the index
    http://localhost:8000/api/appname for an html view of the individual resource
    http://localhost:8000/api/appname/.json for a JSON view of the individual resource
    

    you can check the response in your browser to make sure your URL is working as you expect.

    0 讨论(0)
  • 2021-01-28 05:51

    I had a similar problem, but found that it was the company's proxy that was preventing from pinging myself.

    503 Reponse when trying to use python request on local website

    Try:

    >>> import requests
    >>> session = requests.Session()
    >>> session.trust_env = False
    >>> r = session.get("http://localhost:5000/")
    >>> r
    <Response [200]>
    >>> r.content
    'Hello World!'
    
    0 讨论(0)
提交回复
热议问题