44 lines
1.3 KiB
Plaintext
44 lines
1.3 KiB
Plaintext
![]() |
include::../description.adoc[]
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
[urllib.request| http://#] library:
|
||
|
----
|
||
|
import urllib.request
|
||
|
|
||
|
authenticationHandler = urllib.request.HTTPBasicAuthHandler() # Noncompliant
|
||
|
authenticationHandler.add_password(None,
|
||
|
'http://www.sonarsource.com/',
|
||
|
'sonaruser',
|
||
|
'secretpass1!')
|
||
|
opener = urllib.request.build_opener(authenticationHandler)
|
||
|
urllib.request.install_opener(opener)
|
||
|
|
||
|
urllib.request.urlopen('http://www.sonarsource.com/credential.html')
|
||
|
----
|
||
|
[httplib2| http://#] library:
|
||
|
----
|
||
|
import httplib2
|
||
|
|
||
|
conn = httplib2.Http(".cache")
|
||
|
conn.add_credentials('sonaruser', 'secretpass1!')
|
||
|
response, content = conn.request("http://www.sonarsource.com/rest/path", "GET") # Noncompliant
|
||
|
----
|
||
|
[requests| http://#] library:
|
||
|
----
|
||
|
import requests
|
||
|
|
||
|
conn = requests.get('http://www.sonarsounce.com/rest/path', auth=('sonaruser', 'secretpass1!')) # Noncompliant
|
||
|
----
|
||
|
[http.client| http://#] library:
|
||
|
----
|
||
|
from http.client import HTTPConnection
|
||
|
from base64 import b64encode
|
||
|
|
||
|
conn = HTTPConnection('www.sonarsource.com')
|
||
|
credential = b64encode(b'sonaruser:secretpass1!').decode('ascii')
|
||
|
conn.request('GET', '/', headers={'Authorization': 'Basic %s' % credential}) # Noncompliant
|
||
|
----
|
||
|
|
||
|
include::../see.adoc[]
|