Hi Guy's,
I am trying to send a request.
When I try to run the code I get an error arrow below the C: in the below line;
verify=r"C:\\Users\Administrator\DEV236.cer"
SyntaxError: can't assign to function call
I have tried a number of combinations - with out the r, c:\ instead of c:\\ etc
No joy.
Hope some one can help.
Thanks,
can you show your full code in python tags, as well as the full traceback you get (in error tags).
Please, use proper tags when post code, traceback, output, etc.
See
BBcode help for more info.
I can put up the full code tomorrow, its on my work pc.
It is to do with a HTTP request and an SSL certificate.
I am not totally sure this is the correct way to do it or if a Python reference needs to be made to the SSL certificate.
It is based on examples I have found. So may be way off.
Glad you replied.
Most likely the error is actually on the previous line, not that one which is indicated in the traceback.
Also, if using raw string, no need to escape the backslash.
verify=r"C:\Users\Administrator\DEV236.cer"
is OK.
import requests
import base64
# Set user and password
UserName = "User"
Password = "Password"
# Encode the username and password here
message = UserName+":"+Password
print(message)
message_bytes = message.encode('ascii')
print(message_bytes)
base64_bytes = base64.b64encode(message_bytes).decode()
print(base64_bytes)
x = requests.get('https://xxxx.xxxx.xxxx.xxxx:8443/xxxx/xxxx/retrieveWetails?No=00000373905', headers={"Authorization": "Basic %s" % base64_bytes}), verify="C:\Desktop\DEV236.cer"
>>> %Run 'HTTP Test.py'
Traceback (most recent call last):
File "C:\Users\Administrator\Documents\HTTP Test.py", line 19
x = requests.get('https://xxxx.xxxx.xxxx.xxxx:8443/xxxx/xxxx/retrieveWetails?No=00000373905', headers={"Authorization": "Basic %s" % base64_bytes}), verify="C:\Desktop\DEV236.cer"
^
SyntaxError: can't assign to function call
Sorry I can not send exact logon credentials
Most move
)
back on last line.
import requests
import base64
# Set user and password
UserName = "User"
Password = "Password"
# Encode the username and password here
#message = UserName+":"+Password
message = f'{UserName}:{Password}'
print(message)
message_bytes = message.encode('ascii')
print(message_bytes)
base64_bytes = base64.b64encode(message_bytes).decode()
print(base64_bytes)
x = requests.get('https://xxxx.xxxx.xxxx.xxxx:8443/xxxx/xxxx/retrieveWetails?No=00000373905', headers={"Authorization": f"Basic {base64_bytes}"}, verify=r"C:\Desktop\DEV236.cer")
New error below.
Arrow below y of verify.
verify="C:\Desktop\NFUJDEV236.cer")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 10-11: malformed \N character escape
>>>
Thanks,
Look at my code one more time you will see a
r
.
So no singe
\
in path because of escape character.
>>> verify="C:\Desktop\NFUJDEV236.cer"
File "<interactive input>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 10-11: malformed \N character escape
>>> verify=r"C:\Desktop\NFUJDEV236.cer"
>>> verify
'C:\\Desktop\\NFUJDEV236.cer'
Hi Guy's,
Is there an URL that requires SSL and I can get the associated certificate, so I can test.
As I cant really give details out, which makes it difficult for others to try and give advice.
I have it working with two other languages. But not Python.
Thanks,