1

Selenium wire is not finding my header with the command request.response.headers['Content-Type']. I tried several Headers that can be found using the chrome dev tool.

Code: from seleniumwire import webdriver

chromedriver = 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'

browser = webdriver.Chrome(chromedriver)
browser.get('https://parents.netherhall.org')

all_requests = browser.requests


for request in browser.requests:
    if request.response:
        print(
            request.path,
            request.response.status_code,
            request.response.headers['active'])#

The error I get is KeyError: 'request-url'

Andersson
  • 47,234
  • 13
  • 52
  • 101
Tudor Popescu
  • 447
  • 4
  • 15
  • Does it opens the site actually in browser? It seem that it fails to get secured content (HTTPs) while if to try get unsecure (HTTP) - works fine... – Andersson Sep 10 '18 at 19:18
  • Going to site is fine, the problem is printing out headers by searching it with the command `request.response.headers[header name])` – Tudor Popescu Sep 10 '18 at 19:20
  • Hmm... I'm getting `text/html; charset=utf-8`, `text/css; charset=utf-8`... when print `request.response.headers['Content-Type']` – Andersson Sep 10 '18 at 19:35
  • @Andersson I don't want to get the header content-type, that was just an example, if you replace the text with active( a header) it won't work. – Tudor Popescu Sep 11 '18 at 16:04
  • 2
    I'm quite sure that [`"Active"` header does not exist](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields), so behavior is expected – Andersson Sep 11 '18 at 16:52
  • [here is the active header](https://imgur.com/a/XJfzZwx), but now I found I don't need that, but the cookie, because that is the only thing that changes. – Tudor Popescu Sep 11 '18 at 16:56
  • Still see no `"Active"` header... In case you need Cookies, I see no sense in this SO ticket... – Andersson Sep 11 '18 at 17:01
  • When I tried out `selenium-wire` for the first time using the [homepage simple example](https://github.com/wkeeling/selenium-wire#simple-example) I also got `KeyError` on `content-type` from line `request.response.headers['Content-Type']`. This is because, for that particular response in the loop, there was no `content-type` header. For the sake of running the *simple example* to completion: replace `request.response.headers['Content-Type']` with `request.response.headers.get('Content-Type')` – Jean Monet Mar 26 '20 at 16:48

0 Answers0