No buffer space. why?

A forum for general discussion of the Python programming language.

No buffer space. why?

Postby RedEyedDog1 » Mon Oct 28, 2013 9:11 am

Can anyone please tell me what this error could mean and how to rectify?

I thought it might of been to do with compiling with an old python who had a different definition of the buffer size but i have used the recommended python3.2.3 now and it still has same error.

Here is the code producing error :
Code: Select all
#!/usr/bin/python

#Template and image loader test program
#This program emulates the comms protocal with the PLC

import socket
import time
import re
import os

def Recv(sock):
    string = sock.recv(1024)
    return string

def Send(sock, string):
    string = string + "\r\n"
    sock.send(string)

#Calculates the size of a file
def File_size(File):
        try:
                File_stats = os.stat(ftp_directory + "/" + File)
                return int(File_stats.st_size)
        except FileNotFoundError: #Catch a file not found error
                print("The File, " + File + ", was requested but the file was not found!")
                return 0

#Calculates the free space on this labeller
def Calculate_free_space():
   total_space = 100000
   used_space = 0
      #add up all the files in the directory
   for File in os.listdir(ftp_directory):
      if os.path.isfile(ftp_directory + "/File") and not File.startswith("."):
         print(File + "\n")
         used_space += File_size(File)
         print(str(used_space))

   free_space = total_space - used_space
   print(str(free_space))
   return free_space


port = 23
sending_files = False
variables = {}
ftp_directory="/home/pi"

get_command = re.compile('!([A-Z]\d+)')
get_value = re.compile('"(.*)"')
get_index = re.compile('"\%V(.*)"')


while 1:

    #Create a socket for the connection to the LABELLER
    labeller_sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

    labeller_sock.bind(('',port))

    labeller_sock.listen(1)

    plc_sock, plc_sock_addr = labeller_sock.accept()

    while 1:
        data = Recv(plc_sock)

        #print(data)

        if "!S100" in data:
            Send(plc_sock, "00000000000000000000000000000000")
        elif "!S16" in data:
            Send(plc_sock, "00000000")
        elif "!S17" in data:
            Send(plc_sock, "00000000")
        elif "!S4" in data:
            Send(plc_sock, "00000000")
        elif "!C" in data:
            Send(plc_sock, "\r\n")
        elif "!M" in data:
            Send(plc_sock, "\r\n")
            value = get_value.findall(data)[0]
            print("Template:" + value)
            variables["W21"] = value      
        elif "!W" in data or "!M" in data:
            variable = get_command.findall(data)[0]
            value = get_value.findall(data)[0]
            print(variable + ":" + value)
            variables[variable] = value
        elif "!V19" in data:
            free_space = Calculate_free_space()
            Send(plc_sock, str(free_space))
        elif "!V" in data:
            variable = get_index.findall(data)[0]
            try:
                value = variables["W" + variable]
            except:
                Send(plc_sock,'')
            else:
                Send(plc_sock, value)


Here is the error :

Code: Select all
root@raspberrypi:/home/pi/Desktop# python3.2 labeller_em.py
Traceback (most recent call last):
  File "labeller_em.py", line 70, in <module>
    if "!S100" in data:
TypeError: Type str doesn't support the buffer API


Could it be possible that he is sending me to many bytes back?

Thanks in advance
RedEyedDog1
 
Posts: 17
Joined: Thu Oct 10, 2013 11:21 am

Re: No buffer space. why?

Postby RedEyedDog1 » Mon Oct 28, 2013 9:59 am

Problem solved : I was told the source code was written for python3.2.3 but alas it was written for python2.6.

This solved my problem straight away :)
RedEyedDog1
 
Posts: 17
Joined: Thu Oct 10, 2013 11:21 am


Return to General Discussions

Who is online

Users browsing this forum: MattTuck and 2 guests