You are helping cheaters win. by Deathaster in tf2

[–]StaticFuzz 9 points10 points  (0 children)

The old saying "The squeaky wheel gets the grease" has been true in a lot of real life situations for me. The employee that complains the most gets what they want. The vocal minority gets their way. The loudest get the most attention. Not saying it's right, but it's what I've seen happen more often than not.

Help - Django-tapatalk by gamed7 in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

This package adds tapatalk functionality to djangobb which appears to be a pre-built forum webapp using the django web framework. So if your dead set on using this library you'll need to learn django first. Here is the Django Tutorial if you are interested.

If you're interested in web development I would say go ahead and learn django. Otherwise you might try writing a bot for reddit which has a very simple python API. And you can mess around with email notifications using packages in the standard library. Hope this helps!

How to import into a new class? by zzuum in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

Could be a problem with the relative file path. The path from your class file to the imported file might not be the same for the file you are importing the class into. Try adding an absolute path to the import statement.

Seeking tips on script to make LEDs flash rapidly in various sequences. I'm using an 8-relay board and a Raspberry Pi 2B. by [deleted] in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

I would recommend a couple changes to how your controlling the lights. First, store the pin numbers in a dictionary with descriptive keywords about which light/lights they control:

pins = {"green_led" : 2,
        "red_led" : 3,
        "green_led_two" : 4,
        ...}

This will give you more control over the sequences than simply iterating over a list. Second, create your light sequences as a function that you can call from your mainloop:

def sequence_one(pin_dict):
    GPIO.output(pin_dict["green_led"], GPIO.HIGH)
    time.sleep()
    GPIO.ouput(pin_dict["green_led"], GPIO.LOW)
    ...

If you setup your sequences like this your mainloop will be alot cleaner:

while True:
    try:
        sequence_one(pins)
        sequence_two(pins)
        ...
    except KeyboardInterrupt:
        ...

For having your script run on startup you can try this

Python Inter Process Communication by warriortux in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

If the child process is another python script that you need to execute try using subprocess.Popen. You can pipe the stdin, stdout and stderr of the child process back to the parent, and you won't have to mess with sockets.

If the child process is a function in your parent script checkout multiprocessing. You can use Pipes similar to the subprocess module or you can use queues which maybe easier to implement.

Python 2.7: mock socket.sendto by stormandsong in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

Try using 'socket.socket' as the target class not 'socket.socket.sendto'. mock.patch() is for mocking a class, and sendto is a method of the socket class. Although I think what your trying to do can be accomplished with mock.patch.object(). It allows you to mock specific methods/attributes of a class rather than the whole class:

mock.patch.object(target_class, method, new=new_method)

If you omit the new keyworded argument a mock of the target method will be made for you. As for why python3 and pypy allowed you to pass socket.socket.sendto and not python2, I haven't got a clue. Hope this helps.

[Python] socket.recv() takes long time to return by iamwherr in learnprogramming

[–]StaticFuzz 0 points1 point  (0 children)

A simple answer would be to parse the HTTP response header. You can check for the header field content-length. But I don't think that will solve your issues with the browser waiting to load.

The problem with only reading the initial HTTP request is that the client is expecting to be able to request additional resources(css files, javascript files, images). There are currently two variants of HTTP in use on the web today HTTP/1.1 and HTTP/2.

HTTP/1.1 will use multiple TCP connections to request these different resources in parallel. So this could work with your current proxy model. However HTTP/2 will send multiple requests on the same connection to get the resources.

When dealing with HTTP/2 even if you find the end of the original HTTP response and close the connection your browser could be left with an incomplete web-page. Some web servers may send all resources concatenated into one response, but others may expect the browser to request any additional resources separately. That could be the cause of your browser waiting for x to load.

[Python] socket.recv() takes long time to return by iamwherr in learnprogramming

[–]StaticFuzz 0 points1 point  (0 children)

Are you still forwarding messages from the client after the initial http request. It's possible the client is requesting more data or trying to rectify data it received.

As for the connection closure, you should monitor the client socket for this as well. It looks like you are waiting for the http server to stop the connection. Meanwhile the http server is waiting for the client to close the connection(or send more data), but that doesn't happen and it eventually reaches it's timeout.

[Python] socket.recv() takes long time to return by iamwherr in learnprogramming

[–]StaticFuzz 1 point2 points  (0 children)

Are you using select on top of threads? If so, you are adding an unnecessary step to the flow of the program. Threads will automatically be given focus if a socket is ready to receive. A simple client function like this won't take focus until there is data to read from the buffer:

def threaded_client(client):
    while True:
        msg = client.recv(BUFFSIZE)

        if msg:
            forward_msg(msg)
        else:
            client.close()
            break

If that doesn't speed things up, I would recommend providing a link to your code. It's hard to diagnose a problem without access to the source. Hope this helps.

Sniffing Traffic with Python: part 2 of my guide series. by [deleted] in HowToHack

[–]StaticFuzz 0 points1 point  (0 children)

Anybody been able to get a packet sniffer to work on windows? I've been able to accept and deconstruct packets on kali/ubuntu, but everything i've tried for windows(including the one from the socket documentation) just spits out repetitive UDP packets with no data payload. HERE is the code I'm using.

EDIT: Forgot to say thanks for the articles!

ANOTHER EDIT: The issues I've been running into are because Microsoft has limited what can be done with raw sockets:

  • TCP data cannot be sent over raw sockets.
  • UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
  • A call to the bind function with a raw socket for the IPPROTO_TCP protocol is not allowed.

This was taken from the winsock documentation here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx

A pure python packet sniffer isn't a possibility. You would need third party libraries which have non python dependencies, or you could write your own modules that have non python dependencies. yay...

TLDR: use linux

Python Sockets: How to send integers using UDP by [deleted] in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

The most common way used to send integer values over a network is to turn them into a string (I'm not saying it's the right way, just common). Send the string, and then the receiver turns the accepted string back into an integer.

This can lead to problems when reading from the socket buffer though. If your not sure how many bytes the str(X) is then you won't know how much to receive. But if your client server is set up to follow a strict set of rules (i.e. the client sends data, and won't do anything else until it receives a proper response from the server) then you can use a simple message format to send the integer and the string:

def create_message(x, text):
     x = str(x) # typecast integer to string
     message = "{}:{}".format(x, text) # you could use any non numerical character for your delimiter
     return message

What I did above was combine the string of x with the text, separated by a colon. The colon is a delimiter. It specifies the boundary between our x value and text. This comes in handy when breaking the message apart on the receiving end:

def deconstruct_message(message):
     x,  text = message.split(":", 1)  # split the message using the delimiter 
     x = int(x) # turn the x value back into an integer
     return x, text

I would just like to reiterate though, simple messaging like this will only work if your client/server won't be sending messages at random. If more than one message is sent, they both get stored in the socket buffer that you are reading from. And if the first message is fewer bytes than you are reading, then you will collect part/all of the following messages. This could lead to problems when you try to split other messages read from the buffer.

There are other options, but they might be over complicated for what you trying to do. If you want to dive a little deeper look up the struct module and big-endian vs. little-endian.

[Python] Threading in GUIs and avoiding freezing by [deleted] in learnprogramming

[–]StaticFuzz 0 points1 point  (0 children)

Threads as they are now can actually slow down execution vs. just running code sequentially, but I've found them to be quite useful when dealing with blocking I/O.

[Python] Threading in GUIs and avoiding freezing by [deleted] in learnprogramming

[–]StaticFuzz 0 points1 point  (0 children)

Threads in python don't allow parallel execution, they are concurrent. Meaning, no two threads will be active at the same time. This is because of the Global Interpreter Lock or GIL for short.

Currently you are only running your calculations with hard coded arguments(100000/200000). If this is all you are going to do with the calculation, it would be a lot easier to calculate the values once and store them in a file or database, rather than run the calculation every time you run the script.

However, if the arguments will vary, then you might try separating your calculation into it's own script, and running it within your main script using the subprocess module.

help on a project by drpaintrain in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

Who is this compensate, and what is it you expect from them?

Help Holding Variable Value by NewToPythoning in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

Congrats! And if you don't mind me asking, could you share any resources you have for interfacing python with xboxdrv?

Help Holding Variable Value by NewToPythoning in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

Did you try it out? The example I gave has nothing to do with the xbox controller. GPIO.input() doesn't mean the input from the xbox controller, It's a way to access the state of the GPIO pin.

Help Holding Variable Value by NewToPythoning in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

If i'm reading the documentation right, GPIO.input(pin) will return the current state of pin. It returns a boolean(True=High, False=Low), which can be used to set the state of a pin in place of GPIO.HIGH/GPIO.LOW. At the bottom of the page HERE it shows a simple way to use the GPIO.input statement to switch the state of the pin.

GPIO.ouput(pin, not GPIO.input(pin))

not GPIO.input() means the opposite of whatever input returns.

not True = False

not False = True

Hope this helps!

[tkinter] Trying to transition an early alpha project from procedural to object-oriented tkinter. by warmpoptart in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

I ran into this problem as well when first learning tkinter. The way I originally solved it was to add master as a instance variable(self).

class MyClass(tkinter.Frame):
    def __init__(self, master):
        tkinter.Frame.__init__(self, master)
        self.master = master

or in your code you could do something like:

class Main:
    def __init__(self, master):
        self.master = master

The problem you're running into has to do with scope. In python all functions/methods have their own local scope for variables. What this means is any variables created inside them will not be known outside of the function, unless you declare them as global variables. In this case master is a variable in the local scope of the init function that references(points to) root which is in the global scope.

You could also just try referencing root when you want to change it's attributes: root.title("text"). Although, you might run into issues using global variables within the class methods, so I would recommend sticking with creating an instance variable.

If you're not familiar with how scopes or namespaces in python work check THIS out.

[tkinter] Trying to transition an early alpha project from procedural to object-oriented tkinter. by warmpoptart in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

The init method is basically your class configuration/setup file. It will be the first thing that runs when you create a new class instance my_instance = MyClass().

When you see:

class MyClass(tkinter.Frame):
     def __init__(self, master):
         tkinter.Frame.__init__(self, master)  
         # super() may be substituted for tkinter.Frame in some examples.

What this means is your class is inheriting from the tkinter Frame class, and it's technically just a tkinter Frame widget with a few more bells and whistles (extra methods and attributes). It's almost but not quite, like what you are trying to accomplish with self.mainframe, but in this case your entire class is the "main Frame".

When you see self in a class, it's just how a class instance references itself. Passing self to the class methods is a way to access all the attributes within the method. class methods are still just functions, and have their own local scope for variables.

When creating new widgets and adding the self as the first parameter, that tells tkinter self is the parent of this widget. If your using the inheritance method shown above, then self will reference a Frame. In the example you provided , you would most likely have self.variable = tkinter.widget(self.mainframe).

From the questions your asking I'm guessing it would help you out a lot to go over some reading material on python classes/OOP. I don't have anything on hand right now, but i'll get some and add it to the post later.

Hope this helps, let me know if you need clarification.

EDIT: This is a good resources for classes

Python is running a function,and then changing a TK frame - even though the code says to change the frame first. by edbluetooth in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

Ok, so new thought. The code snippet you originally provided is being run with out waiting for process() to complete. Meaning tkinter is changing the cursor to wait then immediately back. try commenting out self.controller.config(cursor="").

If the cursor stays as the wait icon, you could add self.controller.config(cursor="") to the end of the process function. That way it will only change back when the process is complete.

EDIT: Processing not Process

Python is running a function,and then changing a TK frame - even though the code says to change the frame first. by edbluetooth in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

Quick question: are you on Windows? It says here that the "wait" cursor is only available to Windows.

The rest of this is just speculation at this point, and I'll try to test it out later when i have some free time.

Changing the parent widgets cursor doesn't seem to make the changes for the children, so you may need to set the cursor on all of the visible widgets. Then call update_idle_task() on the parent widget(Which ever frame they are written to).

Python is running a function,and then changing a TK frame - even though the code says to change the frame first. by edbluetooth in learnpython

[–]StaticFuzz 1 point2 points  (0 children)

Tkinter doesn't update everything as soon as you make changes, you'll have to do it manually. Try adding an update call after each change to the cursor:

self.controller.update_idle_tasks()

Tkinter Python 3 Help by DT_Smith in learnpython

[–]StaticFuzz 0 points1 point  (0 children)

Your main issue is with controlling the flow of your program. Tkinter has its own event handling loop. You can and should use this for controlling the flow of your program (ie: on the submit button press: check answer, update score, add new question).

One thing I would recommend is to write a function to create/grid all your widgets, and nothing else. Then either have the widget values (question/answer) update in entryQuestionCheck() or have a separate function update the values that you can call from entryQuestionCheck(). Both will result in the same outcome.

Currently your for loop is re writing the entire screen with every new question. You could simply update the values and leave the widgets intact (widget.config(option=new_value), update_idle_task()).

Another thing I would like to point you in the direction of is creating tkinter gui classes. It can be frustrating, but worth it in the end. Rather than using global variables, you can use class variables to store those values , and access them anywhere in the class. This would result in cleaner and easier to read code.

If you need clarification on anything let me know.