urllib2.URLError:urlopen error[Errno -3]Temporary failure in name resolution+List Index out of range

Hello, Sorry for disturbing you

to briefly explain, I found a bot on twitter that references the RSI (indicator used in trading) it’s a float value.

Every 5 minutes the Bot posts the lowest RSIs of crypto currencies. My goal is to grab the RSI crypto currencies and then analyze them. I also grab Cryptocurrency Volume through a module developed through an API on the site bittrex.com. For this step everything works fine I have no problem.

I’m using tweepy for the twitter stream listener0

Here is an example of a tweet format that is posted:

5 min #RSI Signals:

$BTC - $SLR: 35.85
$BTC - $VRM: 36.5
$BTC - $BCC: 36.52
$BTC - $ENG: 37.81
$BTC - $WAVES: 39.8

$ZCL $CLOAK $PKB $SC

I manage to get the coin  and the RSI no worries.

The problem is that I run it on my OVH server (under Linux) and that I let it run 24/24 permanently through screen command.

By doing this I realized that sometimes I got two recurring errors that I could not solve.

The first is urllib2.URLError: <urlopen error [Errno -3] Temporary failure in name resolution

I do not know where it can come from, sometimes I get this error even after rebooting my VPS but it continues.

I do not know if it’s because I make too many requests on twitter or on bittrex.com knowing that it’s 1 tweet every 5 minutes that I check the volume that if the RSI is less than a some value, what happens once every hour. So I find it fishy.

The second error is totally irrelevant but sometimes without reason I get a List index out of range.

I do not know which line the error comes from since it tells me the error at the end of the file.

This is my code:

import tweepy
import sys, signal, json, time
from bittrex import bittrex
import datetime
import urllib
import urllib2
import yagmail


# Specify the account credentials in the following variables:
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
gmail_user = ''
gmail_password = ''


target_user = 909009874498940928
api = bittrex('KEY', 'SECRET')



def sigint_handler(signum, frame):
    """Handler for ctrl+c"""
    print '\n[!] CTRL+C pressed. Exiting...'
    sys.exit(0)

signal.signal(signal.SIGINT, sigint_handler)




def SplitTweet(twt):
	file = open("logs.txt","a")
	coin =''
	rsi = 0
	first_letter = twt[:1]
	#if it's 5min RSI
	if '5' in first_letter:
		#before read line per line
		lines = twt.split('\n')
		#Read line per line
		for line in lines:
			btc_balance = api.getbalance("BTC")['Available']
			#Split to get $BTC and the rest
			split = line.split("-", 1)
			if '$BTC' in split[0]:
				#Split into all things
				split_coin = split[1].split("$", 1)
				#Only coin and RSI
				coin_et_rsi = split_coin[1]
				coin_et_rsi_split = coin_et_rsi.split(": ", 1)
				coin = coin_et_rsi_split[0]
				rsi_string = coin_et_rsi_split[1]
				rsi = float(rsi_string)
				open_order = api.getopenorders("BTC-" + coin)
				if coin != 'MTL' and coin != 'TRIG':
					if not open_order:
						market = "BTC-" + coin
						marketsummary = api.getmarketsummary(market)
						volume_str = marketsummary[0]['BaseVolume']
						volume = float(volume_str)
						if rsi< 24.1 and volume >=200:
							if btc_balance > 0.028:
								print '\n[+] {} has a RSI of {} '.format(coin, rsi)
								print 'BTC Balance {} BTC\n\n'.format(btc_balance)
								file.write(" %s %s RSI: %s " % (market, datetime.datetime.now(), rsi))
								pricecoin = api.getticker("BTC-" + coin)
								pricebuy = pricecoin['Last']
								pricesell = pricebuy + (0.036 * pricebuy)
								stoploss = pricebuy - (0.04 * pricebuy)
								subject = '%s RSI: %s' %(coin, rsi)
								body = '%s RSI is: %s\nPlaced a buy order at %s and sell order at %s\nYou should place a stop loss at %s\n' %(coin, rsi,pricebuy, pricesell, stoploss)
								yag = yagmail.SMTP(gmail_user, gmail_password)
								yag.send("zidanesignal@gmail.com", subject, body)
							else:
								print 'BTC balance < 0 : {}\n\n'.format(btc_balance)
	file.close()


# This listener will print out all Tweets it receives
class PrintListener(tweepy.StreamListener):
    def on_data(self, data):
        # Decode the JSON data
        tweet = json.loads(data)
	#Reading tweet
	twt = (tweet['text'].encode('ascii', 'ignore'))
	SplitTweet(twt)

    def on_error(self, status):
        print(status)


if __name__ == ' __main__':
    listener = PrintListener()

    # Show system message
    print('Waiting for tweets ...')

    # Authenticate
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    # Connect the stream to our listener
    stream = tweepy.Stream(auth, listener)
    stream.filter(follow=[unicode(target_user)])

And this is the bittrex.py file:

#!/usr/bin/env python
import urllib
import urllib2
import json
import time
import hmac
import hashlib

class bittrex(object):

    def __init__ (self, key, secret):
        self.key = key
        self.secret = secret
        self.public = ['getmarkets', 'getcurrencies', 'getticker', 'getmarketsummaries', 'getmarketsummary', 'getorderbook', 'getmarkethistory']
        self.market = ['buylimit', 'buymarket', 'selllimit', 'sellmarket', 'cancel', 'getopenorders']
        self.account = ['getbalances', 'getbalance', 'getdepositaddress', 'withdraw', 'getorder', 'getorderhistory', 'getwithdrawalhistory', 'getdeposithistory']


    def query(self, method, values={}):
        if method in self.public:
            url = 'https://bittrex.com/api/v1.1/public/'
        elif method in self.market:
            url = 'https://bittrex.com/api/v1.1/market/'
        elif method in self.account:
            url = 'https://bittrex.com/api/v1.1/account/'
        else:
            return 'Something went wrong, sorry.'

        url += method + '?' + urllib.urlencode(values)

        if method not in self.public:
            url += '&apikey=' + self.key
            url += '&nonce=' + str(int(time.time()))
            signature = hmac.new(self.secret, url, hashlib.sha512).hexdigest()
            headers = {'apisign': signature}
        else:
            headers = {}

        req = urllib2.Request(url, headers=headers)
        response = json.loads(urllib2.urlopen(req).read())

        if response["result"]:
            return response["result"]
        else:
            return response["message"]


    def getmarkets(self):
        return self.query('getmarkets')

    def getcurrencies(self):
        return self.query('getcurrencies')

    def getticker(self, market):
        return self.query('getticker', {'market': market})

    def getmarketsummaries(self):
        return self.query('getmarketsummaries')

    def getmarketsummary(self, market):
        return self.query('getmarketsummary', {'market': market})

    def getorderbook(self, market, type, depth=20):
        return self.query('getorderbook', {'market': market, 'type': type, 'depth': depth})

    def getmarkethistory(self, market, count=20):
        return self.query('getmarkethistory', {'market': market, 'count': count})

    def buylimit(self, market, quantity, rate):
        return self.query('buylimit', {'market': market, 'quantity': quantity, 'rate': rate})

    def buymarket(self, market, quantity):
        return self.query('buymarket', {'market': market, 'quantity': quantity})

    def selllimit(self, market, quantity, rate):
        return self.query('selllimit', {'market': market, 'quantity': quantity, 'rate': rate})

    def sellmarket(self, market, quantity):
        return self.query('sellmarket', {'market': market, 'quantity': quantity})

    def cancel(self, uuid):
        return self.query('cancel', {'uuid': uuid})

    def getopenorders(self, market):
        return self.query('getopenorders', {'market': market})

    def getopenorders_special(self):
        return self.query('getopenorders')

    def getbalances(self):
        return self.query('getbalances')

    def getbalance(self, currency):
        return self.query('getbalance', {'currency': currency})

    def getdepositaddress(self, currency):
        return self.query('getdepositaddress', {'currency': currency})

    def withdraw(self, currency, quantity, address):
        return self.query('withdraw', {'currency': currency, 'quantity': quantity, 'address': address})

    def getorder(self, uuid):
        return self.query('getorder', {'uuid': uuid})

    def getorderhistory(self, market, count):
        return self.query('getorderhistory', {'market': market, 'count': count})

    def getwithdrawalhistory(self, currency, count):
        return self.query('getwithdrawalhistory', {'currency': currency, 'count': count})

    def getdeposithistory(self, currency, count):
        return self.query('getdeposithistory', {'currency': currency, 'count': count})

Many thanks in advance for all your answers

Best regards