Exception in file . py

Asked

Viewed 62 times

1

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+'" />\0')
            XML = et.fromstring(Socket.recv(1024).strip('\0')).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+'" />\0')
                    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 chat ID and choose whether I want proxies or not returns me 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: http://prntscr.com/55tzbi OR use my ids.txt http://pastebin.com/353eebdH

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

1 answer

0

The mistake you’re making is that zat_id is being accessed without being set in:

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

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

To capture only file-related exceptions add IOError and 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 mistake 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 catches for this reason.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.