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.

"urlopen error no host given" occurred by referring to an empty proxy env params

See original GitHub issue

Reproducible in:

There sets empty HTTP_PROXY environment param at first.

export HTTP_PROXY=""
import logging, os

logging.basicConfig(level=logging.DEBUG)

from slack_sdk import WebClient

proxy_url = (
    os.environ.get("HTTPS_PROXY")
    or os.environ.get("https_proxy")
    or os.environ.get("HTTP_PROXY")
    or os.environ.get("http_proxy")
)

print(proxy_url)  # this param is void ("") but it's available

client = WebClient(os.environ["SLACK_BOT_TOKEN"])

response = client.chat_postMessage(channel="#randam", text="hello",)

The Slack SDK version

slack-sdk==3.8.0 slackbot==1.0.0 slackdown==0.0.3 slacker==0.14.0

Python runtime version

Python 3.8.10

OS info

WSL2 (Ubuntu 20.04) on Windows10

Steps to reproduce:

running sample code

Expected result:

If proxies on environment params are empty, I’d like to let these params ignore.

Actual result:

There below behavior has occurred.

ERROR:slack_sdk.web.base_client:Failed to send a request to Slack API server: <urlopen error no host given>

Requirements

I would like you to merge below patch.

diff --git a/slack_sdk/proxy_env_variable_loader.py b/slack_sdk/proxy_env_variable_loader.py
index 398bef1..b17219e 100644
--- a/slack_sdk/proxy_env_variable_loader.py
+++ b/slack_sdk/proxy_env_variable_loader.py
@@ -13,8 +13,10 @@ def load_http_proxy_from_env(logger: logging.Logger = _default_logger) -> Option
         or os.environ.get("HTTP_PROXY")
         or os.environ.get("http_proxy")
     )
-    if proxy_url is not None:
+    if (proxy_url is not None) and (proxy_url != ""):
         logger.debug(
             f"HTTP proxy URL has been loaded from an env variable: {proxy_url}"
         )
+    else:
+        proxy_url = None
     return proxy_url

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
srajiangcommented, Aug 3, 2021

Hi @y-adachi-00one 👋 Thank you so much for posting in with this and for proposing a solution- always great to see proposals pushing for better error logging! If you have time to open up a PR for this proposed patch yourself, we always welcome contributions!

Here’s a bit more on contributing to this project if you’re interested.

0reactions
seratchcommented, Aug 4, 2021

@y-adachi-00one Thanks for submitting a pull request! I just quickly reviewed your PR. Let’s discuss details in the review comments

Read more comments on GitHub >

github_iconTop Results From Across the Web

urllib2.URLError: urlopen error no host given - Stack Overflow
Note that this error <urlopen error no host given> can occur if you accidentally set empty string '' as proxy in some other...
Read more >
conan.conf — conan 1.43.4 documentation
You can still specify a default proxy, without a host, which will be used if none of the host names match. If you...
Read more >
What's the 'right' format for the HTTP_PROXY environment ...
If the environment variable REQUEST_METHOD is set, which usually indicates your script is running in a CGI environment, the environment variable ...
Read more >
youtube-dl doesn't feel like downloading anything, ERROR
youtube-dl doesn't feel like downloading anything, ERROR: <urlopen error no host given> (caused by URLError('no host given',)).
Read more >
Requests Documentation - Read the Docs
Errors may occur if you open the file in text mode. ... To give a proxy for a specific scheme and host, use...
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