-2

I was writing a python script to collect data remotely from plc through URL and store those data into my drive in CSV format. I have used the urllib3 module to collect data from the remote device. The problem is whenever I am trying to decode those raw data which is coming from the remote device through URL using this code int(b.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16) the compiler shows a syntax error, but I didn't find anything wrong in this code. I am new to Python as well as Raspberry Pi, please help me to sort out the error.

My full code is

import os
import time
from time import sleep
import datetime
import urllib3


def readVoltage():
    http = urllib3.PoolManager()
    responce = http.request('GET', 'http://northam.ddns.net:9080?HOSTLINK/RVIY*')
    responce1 = http.request('GET', 'http://northam.ddns.net:9080/HOSTLINK/RVIA*')
    responce2 = http.request('GET', 'http://northam.ddns.net:9080/HOSTLINK/RVIB*')
    a, b, c = responce.data, responce1.data, responce2.data
    m = int(a.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)
    n = int(b.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)
    o = int(c.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)
    return m, n, o

def write(volt1, volt2, volt3):
    file.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+str(volt1)+","+str(volt2)+","+str(volt3)+"\n")
    return


file = open("/home/oztron/Documents/datalog.csv", "a")
if os.stat("/home/oztron/Documents/datalog.csv").st_size == 0:
    file.write("Time, volt1, volt2, volt3\n")
while True:
    p, q, r = readVoltage()
    write(p, q, r)
    file.flush()
    time.sleep(2)

The error is

File "test.py", line 15
n = int(b.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)
^
SyntaxError: invalid syntax
2
  • I fixed your code formatting in bulk. Maybe check it to make sure that the indents are in the right place throughout.
    – Brick
    Nov 10, 2017 at 16:57
  • In addition, I would correct the spelling of the 'responce' variables to 'response'. It may seem like nitpicking, but if you've ever had to work on large source files with copy/paste to look for certain names you'd understand.
    – NomadMaker
    Jul 19, 2018 at 10:00

2 Answers 2

1

Your problem is you have mismatched parentheses.

To fix it change these three lines:

m = int(a.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)
n = int(b.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)
o = int(c.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16)

to:

m = int(a.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16))
n = int(b.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16))
o = int(c.decode(("utf-8").spilt('RVI')[1].spilt('*')[0], 16))
0

Check your spelling: 'spilt' is not a Python object method. You want 'split'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.