Emoncms python link error

Hi guys,

 

I wonder if someone with more python experience than my could help shed some light on an intermittent error I've been getting from a python script I use to post data to emoncms. I have an Arduino which receives data from an RF transmitter from my bee hive monitor  connected to a raspberry Pi's USB port. The Arduino sends serial data in JSON format to the Pi. 

 

I've written a simple python script based on emoncms python link which reads from the serial port and posts the data to emoncms.org and a local emoncms. The python script is set to run as a service and output is logged. 

The script runs fine for several weeks then halts with this error, does anyone know what's going on? I'm new to python. I've pasted the script in below:

ERROR:

{A:781},{B:706},{C:987},{D:1837},{E:1244}
('GET', '/input/post.json?apikey=XXXXXXXXXXXXXXXXXX&node=11&json={A:781},{B:706},{C:987},{D:1837},{E:1244}')
ok
('GET', '/emoncms/input/post.json?apikey=XXXXXXXXXXXXXXX&node=11&json={A:781},{B:706},{C:987},{D:1837},{E:1244}')
ok
{A:781},{B:706},{C:987},{D:1837},{E:1244}

{A:781},{B:706},{C:987},{D:1837},{E:1244}
('GET', '/input/post.json?apikey=XXXXXXXXXXXXXXXX&node=11&json={A:781},{B:706},{C:987},{D:1837},{E:1244}')
ok
('GET', '/emoncms/input/post.json?apikey=XXXXXXXXXXXXXX&node=11&json={A:781},{B:706},{C:987},{D:1837},{E:1244}')
ok
{A:781},{B:706},{C:987},{D:1837},{E:1244}

{A:781},{B:706},{C:987},{D:1837},{E:1244}
('GET', '/input/post.json?apikey=XXXXXXXXXXXXXXf&node=11&json={A:781},{B:706},{C:987},{D:1837},{E:1244}')
Traceback (most recent call last):
  File "/home/pi/EmoncmsPythonLink/./pylink.py", line 39, in <module>
    conn.request("GET", "/input/post.json?apikey=4e0e302f4b6dfa38669c80aaac17d2cf&node="+str(nodeid)+"&json="+post_linestr)
  File "/usr/lib/python2.7/httplib.py", line 962, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 996, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 958, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 818, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 780, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 761, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

 

PYTHON SCRIPT:

 

#!/usr/bin/env python

import serial, sys, string
import httplib

# Domain you want to post to: localhost would be an emoncms installation on your own laptop
# this could be changed to emoncms.org to post to emoncms.org
domain = "localhost"
domain2 = "emoncms.org"

# Location of emoncms in your server, the standard setup is to place it in a folder called emoncms
# To post to emoncms.org change this to blank: ""
emoncmspath = "emoncms"

# Write apikey of emoncms account
apikey = "XXXXXXXXXXXXXXXXX"

# Node id youd like the emontx to appear as
nodeid = 11

# Set this to the serial port of your emontx and baud rate, 9600 is standard emontx baud rate
ser = serial.Serial('/dev/ttyUSB0', 9600)

while 1:

  # Read in line of readings from emontx serial

  linestr = ser.readline()

  print linestr
  post_linestr = linestr.rstrip()
  print post_linestr

  # Send to emoncms.org
  conn = httplib.HTTPConnection(domain2)
  print ("GET","/input/post.json?apikey=xxxxxxxxxxxxxxxxxx&node="+str(nodeid)+"&json="+post_linestr)
  conn.request("GET", "/input/post.json?apikey=4e0e302f4b6dfa38669c80aaac17d2cf&node="+str(nodeid)+"&json="+post_linestr)
  response = conn.getresponse()
  print response.read()

    # Send to local emoncms
  print ("GET", "/"+emoncmspath+"/input/post.json?apikey="+apikey+"&node="+str(nodeid)+"&json="+post_linestr)
  conn = httplib.HTTPConnection(domain)
  conn.request("GET", "/"+emoncmspath+"/input/post.json?apikey="+apikey+"&node="+str(nodeid)+"&json="+post_linestr)
  response = conn.getresponse()