Can someone explain what's happening with the HTTP status? - cookies

I get a 404 error while checking the link using requests library for the page below while the page opens fine in the browser when I reach to it from it's parent page. Can someone please help me understand what's happening?. I get the same error using this service as well.
url = "http://www.dell.com/en-us/learn/assets/shared-content~data-sheets~en/documents~2016-v5-systems-oem-10022706.pdf"
response = requests.get(url)
print response.status_code

The first URL sets a cookie, that is sent to the server as you request the second link. If you call the second link with exactly the same request, excluding the cookie, you get a 404.

Related

Flask not automatically redirecting to the signin page

When a session expires and the user tries to access an unauthorized page, the following message occurs (which is correct):
Redirecting...
You should be redirected automatically to target URL: /auth/sign_in. If not click the link.
The problem is that it doesn't actually redirect, I have to click on the auth/sign_in link every time - flask is not automatically redirecting me, just displaying the page. I've tested in Chrome and Firefox, same issue. I searched stack overflow a couple of times but could only find advice on fixing flask redirect, not this specific issue.
Here is my login_manager.unauthorized_handler.
#login_manager.unauthorized_handler
def unauthorized():
flash("Please sign in to access", 'red')
return redirect(url_for("auth.sign_in")), 401
Please let me know if there's anything else that will be helpful to show to answer the question.
Browsers use the 301 (moved permanently) error to redirect to other pages. This is why Flask automatically returns a 301 when redirecting. So if you return a 401 (unauthorized) error your browser won't be able to redirect.
Either return 301 or just leave it blank.
return redirect(url_for("auth.sign_in")), 301
or
return redirect(url_for("auth.sign_in"))
should work.

Qt GET request strange response

I'm writing a program to log into a game a get some information from the account.
After making a post request with username and password, I make a get request in the same location in order to download the needed html source.
However, doing qDebug()<<QString(reply->readAll());
prints "\u001F?\b" ,instead of the entire source code of the page.
The get reply has status code 200, and the error() function returns NetworkError(NoError).
For the post and get requests I'm using header information obtained from chrome's network tab in developer options combined with cookies obtained from previous response headers.
I'm doing a get request after the log-in post request because that's what seems to happen in the actual webpage, as displayed in developer options.
The response might be gzipped. Does unzipping happen to yield the expected result?

Incorrect HTTP Status code

I get a 404 error while checking the link using requests for the page below while the page opens fine in the browser. Can someone please help me understand what's happening?. I get the same error using this service as well.
url = "http://www.dell.com/en-us/learn/assets/corporate~case-studies~en/documents~2014-chitale-dairy-10012962-networking-blades-support.pdf
response = requests.get(url)
print response.status_code
Seems that Hypertext Transfer Protocol is working fine! The pdf file that you trying access is no longer exist or never existed.

website be opened with redirection from stranger domaine

my problem is:
I own a website developed with django framework and uploaded in heroku.
my domain is "OnlyMyDomain.com", but "StrangeDomaine.com" calls my website with a redirect. in other words when you go to StrangeDomaine.com, my website is opened even if the address change to OnlyMyDomain.com.
I tried in my settings.py:
DEBUG = False
ALLOWED_HOSTS = ['OnlyMyDomain.com']
Please can someone explain to me where the problem is coming from? and how can I avoid it?
There is no problem. It seems that you define a permanent redirection (301) from StrangeDomain.com to OnlyMyDomain.com. Then request url will be updated, then StrangeDomain.com becomes OnlyMyDomain.com. If you want to avoid that, just remove this redirection.
The HTTP response status code 301 Moved Permanently is used for
permanent URL redirection, meaning current links or records using the
URL that the response is received for should be updated. The new URL
should be provided in the Location field included with the response.
Wiki : HTTP 301

how to debug facebook app/django setup (url is not valid...)

I'm trying to set up a facebook app using django by following this tutorial: http://www.rkblog.rk.edu.pl/w/p/example-facebook-application-django/ . I get to the point where I start my development server at (manage.py runserver 0.0.0.0:80)
then it says: Now under http://apps.facebook.com/NAME/ you should see a basic Facebook app comming from your server:
I, however, get an error message:
The URL http://my.ip/my_app_name/ is not valid.
I think I've set things up properly:
Canvas Page URL:
http://apps.facebook.com/my_app_name/
Canvas Callback URL
http://my.ip/my_app_name/
Question: how do I go about finding out what's wrong?
Thanks in advance!
Martin
update: when i visit http://my.ip/myappname/, it redirects to http://apps.facebook.com/my_app_name/?auth_token=eac7bf38fb5e591c55ddc458d16dc9b7
where i get the 'url not valid' message... However, when I paste the url with auth_token in it, django serves the requested page as expected... why is facebook saying the url is not valid if in fact it is...?
Is your router set up to forward requests on port 80 to your development machine? If not, you will get an error, as the way Facebook apps work is that Facebook's servers contact your server, get the content, then parse it and re-serve it back to the client.
I actually find with Facebook apps that the easiest thing to do is what you describe in your last sentence - get the auth_token URL, then paste it locally and work from there.