Python Forum

Full Version: c:\... Syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(Jan-11-2021, 06:00 AM)Aussie Wrote: [ -> ]I have it working with two other languages. But not Python.
Do you get any error? Because above is not very helpful to diagnose the problem.

And looking at the URL - is it really retrieveWetails or this is typo (W instead of D)?
(Jan-11-2021, 06:00 AM)Aussie Wrote: [ -> ]I cant really give details out,

We don't need/want your credentials, but if it is public API we can have a look at the docs (if you share details).
Is it possible to turn the ssl verification off?
Thanks,
(Jan-12-2021, 10:01 AM)Aussie Wrote: [ -> ]Is it possible to turn the ssl verification off?
how should we know? We know next to nothing about that API. You share nothing about it (I don't mean you to share your credentials). We don't even know is it some internal API or public API.
import requests
import base64
# Set user and password
UserName = "Xxxxxx"
Password = "Xxxxxx"
# 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://api.xxx.corporate.xxxx.internal:443/xxxx/xxxxx/Details?RequestNo=000002729077",headers={"Authorization": f"Basic {base64_bytes}"}')

print(x.text)
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1076)
(Jan-12-2021, 10:01 AM)Aussie Wrote: [ -> ]Is it possible to turn the ssl verification off?

try pass verify=False

from the docs:
Quote:Requests can also ignore verifying the SSL certificate if you set verify to False:


>>> requests.get('https://kennethreitz.org', verify=False)
<Response [200]>
Note that when verify is set to False, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify to False may be useful during local development or testing.

earlier, I was think about something else...
Hi, I have tried a number of syntax combinations.
I am hoping there is one still remaining that I have not.
Surely it shouldn't be this difficult.
I have searched the web and not found anything that works.

with verify=r'c:\Xxxx\Xxxxxxxxxx\Desktop\DEV236.cer'
I get an error as below
SyntaxError: EOL while scanning string literal
and an arrow appears below the r of cer.
Thanks,
(Jan-08-2021, 08:51 AM)buran Wrote: [ -> ]can you show your full code in python tags, as well as the full traceback you get (in error tags).
import requests
import base64
from requests.auth import HTTPBasicAuth
myobj=""
# 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)
#r = requests.get('https://petstore.swagger.io/v2/pet/findByStatus?status=sold')
r = requests.post('https://xxx.xxx.xxxxxx.xxxxxx.xxxxxx:569/xxxx/xxxx/Details?workRequestNo=000002729055', headers={"Authorization": f"Basic {base64_bytes}, verify=r'c:\Users\Administrator\Desktop\DEV236New.cer')

print(r)
print(r.text)
>>> %Run RequestTest.py
Traceback (most recent call last):
File "C:\Users\Administrator\Documents\RequestTest.py", line 17
r = requests.post('https://xxx.xxx.xxxxxx.xxxxxx.xxxxxx:569/xxxx/xxxx/Details?workRequestNo=000002729055', headers={"Authorization": f"Basic {base64_bytes}, verify=r'c:\Users\Administrator\Desktop\DEV236New.cer')
^
SyntaxError: EOL while scanning string literal
>>>

This is the best copy I can post

Actually ^ under '
The "Swagger Pet Store" works
SyntaxError is mostly basic errors that should be easier to spot👀
Here missing " and } on line 17,you could just have copied my code that dos not has this error.
import requests
import base64
from requests.auth import HTTPBasicAuth
myobj=""
# 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)
#r = requests.get('https://petstore.swagger.io/v2/pet/findByStatus?status=sold')
r = requests.post('https://xxx.xxx.xxxxxx.xxxxxx.xxxxxx:569/xxxx/xxxx/Details?workRequestNo=000002729055', headers={"Authorization": f"Basic {base64_bytes}"}, verify=r'c:\Users\Administrator\Desktop\DEV236New.cer')

print(r)
print(r.text)
Pages: 1 2