question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting host header causes a python casting error

See original GitHub issue

I get a TypeError when trying to request a URL and passing a Host header to it. I tried with quotes and without, but nothing works.

See the following example where prefixing m. to the hostname causes an error:

$ http -v http://m.youtube.com Host:m.youtube.com

http: error: TypeError: Cannot mix str and non-str arguments

Compared to:

$ http -v http://m.youtube.com Host:youtube.com
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: youtube.com
User-Agent: HTTPie/0.9.6



HTTP/1.1 301 Moved Permanently
Content-Length: 0
Content-Type: text/html
Date: Thu, 22 Sep 2016 12:53:56 GMT
Location: http://www.youtube.com/
Server: YouTubeFrontEnd
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block

The same request with curl works properly so definitely looks like something’s off on httpie.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bbamschcommented, Oct 14, 2016

This issue has been resolved in the requests library. https://github.com/kennethreitz/requests/issues/3597

0reactions
gonzalocasascommented, Oct 14, 2016

Thanks @bbamsch !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid HTTP_HOST header error? - Stack Overflow
When Django validates the host from the HTTP request it attempts to match it against the following regex which you can find in...
Read more >
Exception Handling — Python 3.11.1 documentation
The functions described in this chapter will let you handle and raise Python exceptions. It is important to understand some of the basics...
Read more >
Error handling in Azure API Management policies
Learn how to respond to error conditions that may occur during the processing of requests in Azure API Management.
Read more >
NGINX settings - GitLab Docs
For example, to configure HTTP to HTTPS redirection for GitLab, ... you will need to tweak the proxy headers in order to avoid...
Read more >
mod_headers - Apache HTTP Server Version 2.4
The normal mode is late, when Request Headers are set immediately before running the content generator and Response Headers just as the response...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found