http-headers

Python, Flask: How to set response header for all responses

Python, Flask: How to set response header for all responses Question: I want to set all of my http headers responses to something like this: response.headers[“X-Frame-Options”] = “SAMEORIGIN” I checked this question, but it only changes the header for one specific controller. I want to change all of my headers maybe in “before_request” function similar …

Total answers: 3

Change user-agent for Selenium web-driver

Change user-agent for Selenium web-driver Question: I have the following code in Python: from selenium.webdriver import Firefox from contextlib import closing with closing(Firefox()) as browser: browser.get(url) I would like to print the user-agent HTTP header and possibly change it. Is it possible? Asked By: xralf || Source Answers: There is no way in Selenium to …

Total answers: 5

How to get http headers in flask?

How to get http headers in flask? Question: Using Flask, how can I read HTTP headers? I want to check the authorization header which is sent by the client. Asked By: emil || Source Answers: from flask import request request.headers.get(‘your-header-name’) request.headers behaves like a dictionary, so you can also get your header like you would …

Total answers: 4

Scrapy crawl http header data only

Scrapy crawl http header data only Question: (How) can I archieve that scrapy only downloads the header data of a website (for check purposes etc.) I’ve tried to disable some download-middlewares but it doesn’t seem to work. Asked By: Niklas Hantke || Source Answers: Like @alexce said, you can issue HEAD Requests instead of the …

Total answers: 1

Python requests.exception.ConnectionError: connection aborted "BadStatusLine"

Python requests.exception.ConnectionError: connection aborted "BadStatusLine" Question: I am trying to use the Python requests module to issue Http GET commands to access some REST based APIs. The urls are working fine on a RESTClient but when I use the same url in python, I get a connection error. The code I am trying to execute …

Total answers: 4

Python HTTP server send JSON response

Python HTTP server send JSON response Question: What im doing Im trying to get my hands dirty with python and im making a very simple http server so i can send commands to my arduino via serial. Im validating the commands as i sgould and everything works as it ahould be. The concept Im using …

Total answers: 1

Python requests library added an additional header "Accept-Encoding: identity"

Python requests library added an additional header "Accept-Encoding: identity" Question: This is my code. import requests from sys import exit proxies = { “http”: “127.0.0.1:8888”, “https”: “127.0.0.1:8888”, } headers = { “User-Agent”: “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0”, “Accept-Encoding”: “gzip, deflate”, “Accept”: “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”, “Accept-Language”: “en-US,en;q=0.5”, “Connection”: “keep-alive” } login_page = “http://www.test.com/login/” r = …

Total answers: 2

Setting HTTP status code in Bottle?

Setting HTTP status code in Bottle? Question: How do I set the HTTP status code of my response in Bottle? from bottle import app, run, route, Response @route(‘/’) def f(): Response.status = 300 # also tried `Response.status_code = 300` return dict(hello=’world’) ”’StripPathMiddleware defined: http://bottlepy.org/docs/dev/recipes.html#ignore-trailing-slashes ”’ run(host=’localhost’, app=StripPathMiddleware(app())) As you can see, the output doesn’t return …

Total answers: 3

Python send POST with header

Python send POST with header Question: I try to build a python script who sends a POST with parameters for extracting the result. With fiddler, I have extracted the post request who return that I want. The website uses https only. POST /Services/GetFromDataBaseVersionned HTTP/1.1 Host: www.mywbsite.fr “Connection”: “keep-alive”, “Content-Length”: 129, “Origin”: “https://www.mywbsite.fr”, “X-Requested-With”: “XMLHttpRequest”, “User-Agent”: …

Total answers: 3

Calculating Content-Length with Python

Calculating Content-Length with Python Question: I’m trying to make a post, however each time I did it, I would get a 411 response error. I’m using the requests library in python. In [1]: r.post(url) Out[1]: <Response [411]> So then I specified the content length h = {‘content-length’ : ‘0’} and try again. In [2]: r.post(url,h) …

Total answers: 3