Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

503 Reponse when trying to use python request on local website

I'm trying to scrape my own site from my local server. But when I use python requests on it, it gives me a response 503. Other ordinary sites on the web work. Any reason/solution for this?

import requests 
url = 'http://127.0.0.1:8080/full_report/a1uE0000002vu2jIAA/'

r = requests.get(url)

print r

prints out

<Response [503]>

After further investigation, I've found a similar problem to mine. Python requests 503 erros when trying to access localhost:8000

However, I don't think he's solved it yet. I can access the local website via the web browser but can't access using the requests.get function. I'm also using Django to host the server.

python manage.py runserver 8080 

When I use: curl -vvv http://127.0.0.1:8080

* Rebuilt URL to: http://127.0.0.1:8080/
*   Trying 10.37.135.39...
* Connected to proxy.kdc.[company-name].com (10.37.135.39) port 8099 (#0)
* Proxy auth using Basic with user '[company-id]'
> GET http://127.0.0.1:8080/ HTTP/1.1
> Host: 127.0.0.1:8080
> Proxy-Authorization: Basic Y2FhNTc2OnJ2YTkxQ29kZQ==
> User-Agent: curl/7.49.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: BlueCoat-Security-Appliance
< Location:http://10.118.216.201
< Connection: Close
<
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>
* Closing connection 0
like image 267
Kenny Ho Avatar asked Nov 04 '16 19:11

Kenny Ho


Video Answer


1 Answers

I cannot request a local url using python requests because the company's network software won't allow it. This is a dead end and other avenues must be pursued.

EDIT: Working Solution

>>> import requests
>>> session = requests.Session()
>>> session.trust_env = False
>>> r = session.get("http://127.0.0.1:8080")
>>> r
<Response [200]>
like image 100
Kenny Ho Avatar answered Sep 24 '22 22:09

Kenny Ho