Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
c:\... Syntax
#1
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,
Reply
#2
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.
Aussie likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply
#4
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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"
Reply
#6
>>> %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
Reply
#7
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")
buran likes this post
Reply
#8
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,
Reply
#9
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'
Reply
#10
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,
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020