I'm trying to decode this message below. For some reason I keep getting error. I tried everything on google but no success.
b'6362561400022,B,,\x00\x04\x14\x01\x0bPQ=\n\x15(3\x19\x1a<\x1e\x80\x00\x00\xc8\x04\r\xc6\xb1"\xc4\xf2D\xff\xcb\x02\x0c\xfe\x02\x00\x00\x00\nR\x00\x17\x00\x00\x00\x01'
UPDATE. Found the solution
int("0x" + ''.join([hex(x)[2:] for x in byte_string]), base=16)
Found the answer.
int("0x" + ''.join([hex(x)[2:] for x in byte_string]), base=16)
Related
I am converting some code from python2 to 3 and saw an error that the 2to3 did not catch on a line:
pickle.dumps(('predskew', predskewData[0])) + pickleSep
That produces an error in python3:
pickledPredskewData = pickle.dumps(('predskew', predskewData[0])) + pickleSep
TypeError: can't concat str to bytes
I know from other posts on stack over flow I could perhaps use an encode? or a decode? I just wasn't sure where or what. So I did try this in python2:
pickleSep = ":::::"
pickle.dumps(('predskew',0)) + pickleSep
Which produces:
"(S'predskew'\np0\nI0\ntp1\n.:::::"
Also,
pickle.dumps(('predskew',0)) + pickleSep.encode()
Gives the same result.
Now if I try the same line in python3, I get what 'looks' like vastly different output:
pickle.dumps(('predskew', 0)) + pickleSep.encode()
Gives the output of:
b'\x80\x04\x95\x10\x00\x00\x00\x00\x00\x00\x00\x8c\x08predskew\x94K\x00\x86\x94.:::::'
So not sure my encode fix is the right approach as the answers seem different (unless it is the print just showing me the bytes itself?!)
I have the following script:
hex_string = "c23dba5fcac1048b3c050266ceb6a0e870670021"
hex_bytes = bytearray.fromhex(hex_raw)
print(hex_bytes.reverse())
The problem it prints/returns None. I was wondering, because in this example it works.
Thanks in advance.
I found the issue. The method .reverse() dont return anything, but changes the bytearray, so the code must be:
hex_string = "c23dba5fcac1048b3c050266ceb6a0e870670021"
hex_bytes = bytearray.fromhex(hex_raw)
hex_bytes.reverse()
print(hex_bytes)
I've created a python script that checks muliple different urls and ports and detects if there is an RTSP stream on them - it is working fine, but it creates errors when the stream doesn't exist (which I'd obviously expect).
I'm getting [rtsp # 0x16745c0] method DESCRIBE failed: 451 ERROR
What I want to do it add a line to my script so if I get the above error, then I just display it in a message on screen. I've tried the following with no luck:
for x in feedList:
print("[INFO] Checking Link..." + x)
cap=cv2.VideoCapture(x)
try:
# Check if camera opened successfully
if (cap.isOpened()== True):
streamlink = x
print("[INFO] FOUND! Stream Link..." + x)
break
except socket.error:
print("[NO STREAM]" + x)
except:
print("[FAILED]" + x)
pass
The Except cases never get hit, I always just get [rtsp # 0x16745c0] method DESCRIBE failed: 451 ERROR
Any help would be appreciated.
Thanks
Chris
If the stream on the link does not exist, creating VideoCapture object on that link would still be successful but you will not be able to process on the object.
You code's control flow just might be going in and checking if (cap.isOpened()== True) but there is no else block to handle what would happen if if (cap.isOpened() != True). So just try adding an else block to display the error message.
for x in feedList:
print("[INFO] Checking Link..." + x)
cap=cv2.VideoCapture(x)
try:
# Check if camera opened successfully
if (cap.isOpened()== True):
streamlink = x
print("[INFO] FOUND! Stream Link..." + x)
break
# Else is important to display error message on the screen if can.isOpened returns false
else
print("[NO STREAM]" + x)
except socket.error:
print("[NO STREAM]" + x)
except:
print("[FAILED]" + x)
pass
If this doesn't work: following might solve the issue:
One of the main issues is that every camera manufacturer uses their
own protocol (RTSP URI formatting). Finding the correct URL for your
IP-camera can be frustrating and time-intensive. When found you can
try to open it with VLC, and afterwards with Kerberos.io.
Depending on the format of the RTSP URI things can go wrong, for
example when using a format like above. To solve the problem you'll
need to add an question mark "?" at the end of the url.
As example original link might be:
rtsp://192.168.2.109:554/user=admin&password=mammaloe&channel=1&stream=0.sdp
So with ? it would be:
rtsp://192.168.2.109:554/user=admin&password=mammaloe&channel=1&stream=0.sdp?
Source
This is my code for a particular question on codechef :
n=int(input())
for _ in range(n):
a,b =input().split()
a=int(a)
b=int(b)
x=[int(q) for q in input().split()]
x.sort(reverse=True)
new_x=[item for pos,item in enumerate(x) if x.index(item)==pos]
last=new_x[b]
i=x.index(last)
ans= i - 1 + x.count(last)
print(ans)
It passes all the test cases when I try it on my own environment but shows runtime (NZEC) when I submit the solution.
I searched a lot on internet but not able to figure out the problem.
Please help me out.
I'm trying to create an app that needs to recursively check an email address for new emails and then do some other stuff; I'm having some problems with the getting the body of the emails, though. I'm using the pyzmail module alongside imapclient, and the Automate the Boring Stuff for guidance (with python 3.6). Here's my code:
mail = imapclient.IMAPClient('imap.gmail.com', ssl=True)
mail.login('email', 'password')
mail.select_folder('INBOX', readonly=False)
uid = mail.gmail_search('NC')
for i in uid:
message = mail.fetch(i, ['BODY[]'], 'FLAGS')
msg = pyzmail.PyzMessage.factory(message[i][b'BODY[]'])
msg.html_part.get_payload().decode(msg.text_part.charset)
But it's not working. I've basically tried different forms of this code but to no avail and there's really not that many examples that can help me along. I'm a bit of a python newbie. Can anybody help?
Thanks,
EDIT
I realized where I made a mistake and fixed a bit of the code:
server = imapclient.IMAPClient('imap.gmail.com', ssl=True)
server.login('p.imagery.serv#gmail.com', 'rabbitrun88ve')
server.select_folder('INBOX', readonly=True)
uids = server.gmail_search('NC')
for i in uids:
messages = server.fetch(i, ['BODY[]'])
msg = pyzmail.PyzMessage.factory(messages[b'BODY[]'])
The problem I'm having is with the last line, which I dont know how to fed using the variables that is created with the iterator. It throws out this message:
ValueError: input must be a string a bytes, a file or a Message
I'm not sure if you still have this problem but for those who might have similar issues in future.
I noticed a little omission in the last line which might be the culprit.
msg = pyzmail.PyzMessage.factory(messages[b'BODY[]'])
You omitted the 'i' variable of the for loop
msg = pyzmail.PyzMessage.factory(messages[i][b'BODY[]'])
I'd like to do next to get body text of searched messages:
server = imapclient.IMAPClient('imap.gmail.com', ssl=True)
server.login('p.imagery.serv#gmail.com', 'rabbitrun88ve')
server.select_folder('INBOX', readonly=True)
uids = server.gmail_search('NC')
rawmessage = server.fetch(uids, ['BODY[]'])
for i in rawmessage:
msg = pyzmail.PyzMessage.factory(rawmessage[i][b'BODY[]'])
msg.html_part.get_payload().decode(msg.text_part.charset)
In this case, you get iteration over fetched emails with body text. I checked similar example but I used text_part.get_payload() instead html regarding features of my server.