Exception in .py file

0

I have the following code:

import socket
from xml.etree import ElementTree as et
import math, urllib
import random, time, re
global String_1, String_2, String_3, String_4, Chat, Using_Proxies, Raid_Fixed_j2

def Raid():
    try:
            nxat_ids = [i.strip() for i in open('ids.txt','r').read().splitlines()]
            i = random.choice(nxat_ids)
            nxat_id = i.split('&')
            print("\n" + str(nxat_id))
            ID = zat_id[0]
            ID = zat_id[0].strip('UserId=')
            K1 = zat_id[1]
            K1 = zat_id[1].strip('k1=')
    except:
            print("'ids.txt' was not found! Please create one in the same folder that this script is in and add IDs to it SPECIFALLY IN THIS LAYOUT: http://prntscr.com/55tzbi OR use my ids.txt http://pastebin.com/353eebdH\n")
            time.sleep(999)
    if Using_Proxies == 'yes':
            Proxies_txt = [i.strip() for i in open('socks5.txt','r').read().splitlines()]
            Proxy = random.choice(Proxies_txt)
            proxy = Proxy.split(':')
            print "Proxy Being Used: " + str(Proxy[0]) + ":" + str(Proxy[1]) + "\n"
            try:
                    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, Proxy[0], int(Proxy[1]))
                    test = socks.socksocket
                    Socket = test(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
                    Socket.settimeout(5)
                    Socket.connect(("167.114.19.192", 1204))
            except:
                    print "Could not connect using the selected proxy! Or 'socks5.txt' was not found! Re-trying....\n"
                    Raid()
    elif Using_Proxies != 'yes':
            Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
            Socket.connect(('167.114.19.192', 1204))
            Socket.send('<y r="'+Chat+'" v="0" u="'+ID+'" />
import socket
from xml.etree import ElementTree as et
import math, urllib
import random, time, re
global String_1, String_2, String_3, String_4, Chat, Using_Proxies, Raid_Fixed_j2

def Raid():
    try:
            nxat_ids = [i.strip() for i in open('ids.txt','r').read().splitlines()]
            i = random.choice(nxat_ids)
            nxat_id = i.split('&')
            print("\n" + str(nxat_id))
            ID = zat_id[0]
            ID = zat_id[0].strip('UserId=')
            K1 = zat_id[1]
            K1 = zat_id[1].strip('k1=')
    except:
            print("'ids.txt' was not found! Please create one in the same folder that this script is in and add IDs to it SPECIFALLY IN THIS LAYOUT: http://prntscr.com/55tzbi OR use my ids.txt http://pastebin.com/353eebdH\n")
            time.sleep(999)
    if Using_Proxies == 'yes':
            Proxies_txt = [i.strip() for i in open('socks5.txt','r').read().splitlines()]
            Proxy = random.choice(Proxies_txt)
            proxy = Proxy.split(':')
            print "Proxy Being Used: " + str(Proxy[0]) + ":" + str(Proxy[1]) + "\n"
            try:
                    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, Proxy[0], int(Proxy[1]))
                    test = socks.socksocket
                    Socket = test(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
                    Socket.settimeout(5)
                    Socket.connect(("167.114.19.192", 1204))
            except:
                    print "Could not connect using the selected proxy! Or 'socks5.txt' was not found! Re-trying....\n"
                    Raid()
    elif Using_Proxies != 'yes':
            Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
            Socket.connect(('167.114.19.192', 1204))
            Socket.send('<y r="'+Chat+'" v="0" u="'+ID+'" />%pre%')
            XML = et.fromstring(Socket.recv(1024).strip('%pre%')).attrib
            print('Recieved: ' + str(XML))
            Handshake_yi = int(XML['yi'])
            Handshake_yc = int(XML['yc'])
            Handshake_ys = int(XML['ys'])
            ym1 = str(int(2 << (Handshake_yi % 30)) % Handshake_yc + Handshake_yi)
            print("YM1: " + ym1)
            ym2 = str(int(pow(2, Handshake_ys % 32)))
            print("YM2: " + ym2)
            String_1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
            String_2 = len(String_1) - 1
            String_4 = ''.join([String_1[random.randint(0, String_2)] for y in range(1, 10)])#Null's name
            Avatar = random.randint(1,1000)
            Socket.send('<j2 cb="0" Y="2" ym1="'+str(ym1)+'" ym2="'+str(ym2)+'" q="1" y="'+str(Handshake_yi)+'" k="'+K1+'" p="0" c="'+Chat+'" u="'+ID+'" d0="0" n="'+String_4+'" a="'+str(Avatar)+'" h="" v="0" />')
            while 1:
                    String_3 = ''.join([String_1[random.randint(0, String_2)] for y in range(1, 15)])#Message
                    Data = Socket.recv(1024)
                    Socket.send('<m t="'+String_3+'" u="'+ID+'" />%pre%')
                    Raid()
print("-----------------------------")
print("TheFox's nxat.tk Raid Script")
print("---------------------------\n")
Chat = raw_input("Chat's ID: ")
Using_Proxies = raw_input("Would you like to use proxies? Type 'yes' or 'no' : ")
Raid()
') XML = et.fromstring(Socket.recv(1024).strip('%pre%')).attrib print('Recieved: ' + str(XML)) Handshake_yi = int(XML['yi']) Handshake_yc = int(XML['yc']) Handshake_ys = int(XML['ys']) ym1 = str(int(2 << (Handshake_yi % 30)) % Handshake_yc + Handshake_yi) print("YM1: " + ym1) ym2 = str(int(pow(2, Handshake_ys % 32))) print("YM2: " + ym2) String_1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890' String_2 = len(String_1) - 1 String_4 = ''.join([String_1[random.randint(0, String_2)] for y in range(1, 10)])#Null's name Avatar = random.randint(1,1000) Socket.send('<j2 cb="0" Y="2" ym1="'+str(ym1)+'" ym2="'+str(ym2)+'" q="1" y="'+str(Handshake_yi)+'" k="'+K1+'" p="0" c="'+Chat+'" u="'+ID+'" d0="0" n="'+String_4+'" a="'+str(Avatar)+'" h="" v="0" />') while 1: String_3 = ''.join([String_1[random.randint(0, String_2)] for y in range(1, 15)])#Message Data = Socket.recv(1024) Socket.send('<m t="'+String_3+'" u="'+ID+'" />%pre%') Raid() print("-----------------------------") print("TheFox's nxat.tk Raid Script") print("---------------------------\n") Chat = raw_input("Chat's ID: ") Using_Proxies = raw_input("Would you like to use proxies? Type 'yes' or 'no' : ") Raid()

And when I put the ID of the chat and I choose if I want to proxies or it does not return the following exception:

'ids.txt' was not found! Please create one in the same folder that this script is in and add IDs to it SPECIFALLY IN THIS LAYOUT: link OR use my ids.txt < a href="http://pastebin.com/353eebdH"> link

The worst thing is that I already have the file created in the same folder where the .py file is. What do I do?

    
asked by anonymous 11.02.2017 / 02:41

1 answer

0

The error you are experiencing is that zat_id is being accessed without being set to:

ID = zat_id[0]
ID = zat_id[0].strip('UserId=')
K1 = zat_id[1]
K1 = zat_id[1].strip('k1=')

However the exception will catch any exception, and not just the file opening exceptions, which is the expected behavior.

To capture only file-related exceptions add IOError and you will get the expected feedback.

except IOError:
        print("'ids.txt' was not found! Please create one in the same folder that this script is in and add IDs to it SPECIFALLY IN THIS LAYOUT: http://prntscr.com/55tzbi OR use my ids.txt http://pastebin.com/353eebdH\n")
        time.sleep(999)

Now the error should be something like:

Traceback (most recent call last):
  File "ex.py", line 26, in <module>
    Raid()
  File "ex.py", line 13, in Raid
    ID = zat_id[0]
NameError: global name 'zat_id' is not defined.

We should always avoid using too generic catch-outs for this reason.

I suggest that you take a closer look at what the code does and how the code does, because I think it should be well fixed to work as expected.

    
11.02.2017 / 03:16