Urlopen error errno 2 name or service not known

Hello, We have the xmatters Splunk app installed on our Splunk Cloud SH. It's not sending alerts to xmatters and the xmatters log is coming up with the below. I've tested the app on my own instance and xmatters has tested it on their end and both splunk instances are sending alerts to xmatters. Has ...

Hello,

We have the xmatters Splunk app installed on our Splunk Cloud SH.

It’s not sending alerts to xmatters and the xmatters log is coming up with the below.

I’ve tested the app on my own instance and xmatters has tested it on their end and both splunk instances are sending alerts to xmatters.

Has anyone come across this issue? I think the SH might be having issues when resolving the xmatters URL, but how do I get Splunk Cloud Support to look at this if the app is not supported?

2020-04-05 23:45:37,954 ERROR [xmatters.alert_action.main] [xmatters] [<module>] [14006] <urlopen error [Errno -2] Name or service not known>
Traceback (most recent call last):
  File "/opt/splunk/etc/apps/xmatters_alert_action/bin/xmatters.py", line 143, in <module>
    REQUEST_ID = XM_ALERT.execute()
  File "/opt/splunk/etc/apps/xmatters_alert_action/bin/xmatters.py", line 119, in execute
    request_id = xm_client.send_event(self.endpoint_url, xm_event)
  File "/opt/splunk/etc/apps/xmatters_alert_action/lib/xmatters_sdk/xm_client.py", line 61, in send_event
    force_https=True
  File "/opt/splunk/etc/apps/xmatters_alert_action/lib/common_utils/rest.py", line 160, in post
    return self._send_request(req, headers)
  File "/opt/splunk/etc/apps/xmatters_alert_action/lib/common_utils/rest.py", line 100, in _send_request
    res = urllib2.urlopen(req)
  File "/opt/splunk/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/opt/splunk/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/opt/splunk/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/opt/splunk/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/opt/splunk/lib/python2.7/urllib2.py", line 1241, in https_open
    context=self._context)
  File "/opt/splunk/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno -2] Name or service not known>

@jh0ker It seems to me as still an Issue because I came across this.

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/urllib3/connection.py", line 142, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3.5/site-packages/urllib3/util/connection.py", line 67, in create_connection
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  File "/usr/lib64/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 578, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 351, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 814, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.5/site-packages/urllib3/connection.py", line 254, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.5/site-packages/urllib3/connection.py", line 151, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f111399d630>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/filip/.local/lib/python3.5/site-packages/telegram/utils/request.py", line 132, in _request_wrapper
    resp = self._con_pool.request(*args, **kwargs)
  File "/usr/lib/python3.5/site-packages/urllib3/request.py", line 73, in request
    **urlopen_kw)
  File "/usr/lib/python3.5/site-packages/urllib3/request.py", line 151, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/lib/python3.5/site-packages/urllib3/poolmanager.py", line 165, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 651, in urlopen
    release_conn=release_conn, **response_kw)
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 651, in urlopen
    release_conn=release_conn, **response_kw)
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 651, in urlopen
    release_conn=release_conn, **response_kw)
  File "/usr/lib/python3.5/site-packages/urllib3/connectionpool.py", line 623, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.5/site-packages/urllib3/util/retry.py", line 281, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot<BOT_TOKEN>/sendMessage (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f111399d630>: Failed to establish a new connection: [Errno -2] Name or service not known',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 24, in <module>
    schedule.run_pending()
  File "/home/filip/.local/lib/python3.5/site-packages/schedule/__init__.py", line 367, in run_pending
    default_scheduler.run_pending()
  File "/home/filip/.local/lib/python3.5/site-packages/schedule/__init__.py", line 64, in run_pending
    self._run_job(job)
  File "/home/filip/.local/lib/python3.5/site-packages/schedule/__init__.py", line 96, in _run_job
    ret = job.run()
  File "/home/filip/.local/lib/python3.5/site-packages/schedule/__init__.py", line 293, in run
    ret = self.job_func()
  File "main.py", line 14, in base
    ":kissing_heart:", use_aliases=True))
  File "/home/filip/.local/lib/python3.5/site-packages/telegram/bot.py", line 124, in decorator
    result = func(self, *args, **kwargs)
  File "/home/filip/.local/lib/python3.5/site-packages/telegram/bot.py", line 150, in decorator
    result = self._request.post(url, data, timeout=kwargs.get('timeout'))
  File "/home/filip/.local/lib/python3.5/site-packages/telegram/utils/request.py", line 205, in post
    **urlopen_kwargs)
  File "/home/filip/.local/lib/python3.5/site-packages/telegram/utils/request.py", line 138, in _request_wrapper
    raise NetworkError('urllib3 HTTPError {0}'.format(error))
telegram.error.NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot<BOT_TOKEN>/sendMessage (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f111399d630>: Failed to establish a new connection: [Errno -2] Name or service not known',))
$ pip3 freeze
blivet==1.20.3
borgbackup==1.0.7
certifi==2016.9.26
chardet==2.2.1
coverage==4.2
decorator==4.0.10
dnf-langpacks==0.15.1
emoji==0.3.9
fail2ban==0.9.5
future==0.16.0
iniparse==0.4
initial-setup==0.3.40
langtable==0.0.35
llfuse==1.1.1
msgpack-python==0.4.8
ntplib==0.3.3
ordered-set==2.0.0
pid==2.0.1
pwquality==1.3.0
pygobject==3.20.1
pygpgme==0.3
PyIscsi==1.0
pykickstart==2.25
pyparted==3.10.7
PySocks==1.5.6
python-meh==0.43
python-telegram-bot==5.2.0
pytz==2016.6.1
pyudev==0.21.0
requests==2.10.0
requests-file==1.4
requests-ftp==0.3.1
rpm-python==4.13.0rc1
schedule==0.3.2
six==1.10.0
slip==0.6.4
slip.dbus==0.6.4
SSSDConfig==1.14.2
systemd-python==232
urllib3==1.15.1
You are using pip version 8.0.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
import schedule
import emoji
import time
import telegram

TOKEN = ""  # Some Bot Token
CHAT_ID = 0  # Some CHAT_ID

bot = telegram.Bot(token=TOKEN)

def base():
    bot.sendMessage(chat_id=CHAT_ID, text=emoji.emojize("Message1", use_aliases=True))

def check():
    bot.sendMessage(chat_id=CHAT_ID, text=emoji.emojize("Message2", use_aliases=True))

schedule.every().day.at("22:00").do(base)
schedule.every().day.at("22:10").do(check)

while True:
    schedule.run_pending()
    time.sleep(schedule.idle_seconds())

This also happened on the first from the first run of bot.sendMessage from console, but after second run it worked fine. And Now on this long running script it does the same.

Hi Guys,

I am trying to browse one URL using the urllib module. But it is showing me the below error.

html = urlopen("http://en.wikipedia.org" + articleUrl)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

How can I solve this error?







Jul 15, 2020


in Python


by



• 38,240 points





3,749 views



1 answer to this question.

Related Questions In Python

  • All categories

  • ChatGPT
    (4)

  • Apache Kafka
    (84)

  • Apache Spark
    (596)

  • Azure
    (131)

  • Big Data Hadoop
    (1,907)

  • Blockchain
    (1,673)

  • C#
    (141)

  • C++
    (271)

  • Career Counselling
    (1,060)

  • Cloud Computing
    (3,446)

  • Cyber Security & Ethical Hacking
    (147)

  • Data Analytics
    (1,266)

  • Database
    (855)

  • Data Science
    (75)

  • DevOps & Agile
    (3,575)

  • Digital Marketing
    (111)

  • Events & Trending Topics
    (28)

  • IoT (Internet of Things)
    (387)

  • Java
    (1,247)

  • Kotlin
    (8)

  • Linux Administration
    (389)

  • Machine Learning
    (337)

  • MicroStrategy
    (6)

  • PMP
    (423)

  • Power BI
    (516)

  • Python
    (3,188)

  • RPA
    (650)

  • SalesForce
    (92)

  • Selenium
    (1,569)

  • Software Testing
    (56)

  • Tableau
    (608)

  • Talend
    (73)

  • TypeSript
    (124)

  • Web Development
    (3,002)

  • Ask us Anything!
    (66)

  • Others
    (1,938)

  • Mobile Development
    (263)

Subscribe to our Newsletter, and get personalized recommendations.

Already have an account? Sign in.

  • Home
  • Forum
  • The Ubuntu Forum Community
  • Ubuntu Official Flavours Support
  • Networking & Wireless
  • [SOLVED] Python urllib2 problem: Name or service not known

  1. Python urllib2 problem: Name or service not known

    Hi all,

    Some time ago I’ve written some python code to read video data off an IP camera connected via a router to a laptop. Now I try to run this code on a different laptop and router combination, but now I can’t access the camera.
    Some minimal example code:

    Code:

    import urllib2
    
    url = urllib2.urlopen("http://192.168.1.3/-wvhttp-01-/image.cgi")

    This fails and returns the error:

    Code:

    <urlopen error [Errno -2] Name or service not known

    When I check further, I cannot access any url via urllib2.urlopen, not the camera nor the router nor localhost. Pinging them poses no problem though, and I can access the video feed and the router admin page in firefox without any issues.
    Searching for the problem turned up this discussion on the gentoo forums, which didn’t provide any solution but did hint that it might be a system-related problem rather than a coding problem.
    I run kubuntu 11.10 on the laptop, the router is not connected to the internet and serves as dhcp server for both the laptop and the camera.

    I.


  2. Re: Python urllib2 problem: Name or service not known

    Never mind it’s a proxy problem. I disabled http_proxy in .bashrc for this, but apparently it was also set in /etc/bash.bashrc and I didn’t check for that.

    That did leave me with the problem how I could get my code to work with the proxy enabled. But I found that one too, just put

    Code:

    import os
    os.environ['http_proxy']=''

    before importing urllib2.

    I.


  3. Re: Python urllib2 problem: Name or service not known

    hey Iskendar, I added the import os code into my program but I’m still getting the same error. I’m running ubuntu on a virtual machine and my program is trying to open a lot of urls to try and scrape song lyrics from a site.

    Code:

    from bs4 import BeautifulSoup
    import os
    os.environ['http_proxy'] = ''
    from urllib.request import urlopen
    from urllib.request import urlretrieve
    import re
    
    base = "http://www.hymnal.net/hymn.php/"
    ns_urls = []
    
    #this while loop places all the urls for all the new songs into a list
    ns = 1
    while ns < 391:
    	addr = "ns/" + str(ns)
    	ns_urls.append(base + addr)
    	ns += 1
    
    ns_songs = []
    count = 1
    #this for loop parses the html found in the urls and places the lyrics into a list
    for url in ns_urls:
    	soup = BeautifulSoup(urlopen(url))
    	print(count)
    	count += 1
            """the counter here is see on which url the error arises.
               from what I've seen it changes everytime but is usually around 20 - 40.
    	for tag in soup.find_all('div'):
    		if tag.has_key('class'):
    			if tag['class'][0] == 'main-content':
    				str_tag = str(tag)
    				ns_songs.append(str_tag)


Tags for this Thread

Bookmarks

Bookmarks


Posting Permissions

Понравилась статья? Поделить с друзьями:
  • Urlopen error errno 11003 getaddrinfo failed
  • Usbsafe fatal error
  • Urlmon dll ошибка
  • Usbmux error 92 checkra1n
  • Urllib2 httperror http error 501 https required