Posts: 27
Threads: 7
Joined: Aug 2020
Jan-08-2021, 08:48 AM
(This post was last modified: Jan-08-2021, 09:20 AM by Aussie.)
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,
Posts: 8,158
Threads: 160
Joined: Sep 2016
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.
Posts: 27
Threads: 7
Joined: Aug 2020
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.
Posts: 8,158
Threads: 160
Joined: Sep 2016
Jan-08-2021, 09:48 AM
(This post was last modified: Jan-08-2021, 09:48 AM by buran.)
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.
Posts: 27
Threads: 7
Joined: Aug 2020
Jan-08-2021, 11:00 PM
(This post was last modified: Jan-08-2021, 11:02 PM by Aussie.)
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"
Posts: 27
Threads: 7
Joined: Aug 2020
Jan-08-2021, 11:08 PM
(This post was last modified: Jan-08-2021, 11:08 PM by Aussie.)
>>> %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
Posts: 7,315
Threads: 123
Joined: Sep 2016
Jan-08-2021, 11:27 PM
(This post was last modified: Jan-08-2021, 11:27 PM by snippsat.)
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")
Posts: 27
Threads: 7
Joined: Aug 2020
Jan-10-2021, 09:59 PM
(This post was last modified: Jan-10-2021, 09:59 PM by Aussie.)
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,
Posts: 7,315
Threads: 123
Joined: Sep 2016
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'
Posts: 27
Threads: 7
Joined: Aug 2020
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,
|