0

I wrote this code to send data by query string, but I cannot figure out how to get the '%0A' out of the query sting for the RSSI.

#!/usr/bin/python
import fileinput
import sys
import requests
import socket

for line in fileinput.input():
   if line.startswith("UUID:"):
      a = line.split(" ")[1]
      b = line.split(" ")[3]
      c = line.split(" ")[5]
      d = line.split(" ")[7]
      e = line.split(" ")[9]
      f = socket.gethostname()
      payload = {'uuid': a, 'major': b, 'minor': c, 'power': d, 'rssi': e, 'hubname': f}
      r = requests.get("http://posttestserver.com/post.php", params=payload)
      print(r.url)

The query string looks like this:

http://posttestserver.com/post.php?major=1&hubname=pihub0001&uuid=2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6&power=-71&rssi=-65%0A&minor=1

The data coming into the file looks like this:

iBeacon Scan ...
UUID: 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 MAJOR: 1 MINOR: 1 POWER: -71 RSSI: -61
UUID: 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 MAJOR: 1 MINOR: 1 POWER: -71 RSSI: -68
UUID: 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 MAJOR: 1 MINOR: 1 POWER: -71 RSSI: -68
UUID: 3F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 MAJOR: 1 MINOR: 1 POWER: -71 RSSI: -65
UUID: 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 MAJOR: 1 MINOR: 1 POWER: -71 RSSI: -68

How do I get rid of the '%0A' after the RSSI field in the query string? I'm using Raspbian on a Raspberry Pi.

2 Answers 2

2

%0A is a newline (http://www.asciitable.com/). This is happening because you do not strip the newline when reading the input line. Just add line = line.strip() near the top.

Sign up to request clarification or add additional context in comments.

Comments

1

Well, 0x0a is decimal 10 - and the ascii table says that is new line. So, you could call strip() to trim the String -

e = line.split(" ")[9].strip()

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.