diff --git a/samples/create_extract_task.py b/samples/create_extract_task.py index 8c02fefff..2b59b0bfb 100644 --- a/samples/create_extract_task.py +++ b/samples/create_extract_task.py @@ -41,7 +41,6 @@ def main(): tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=False) - server.add_http_options({"verify": False}) server.use_server_version() with server.auth.sign_in(tableau_auth): # Monthly Schedule diff --git a/samples/create_group.py b/samples/create_group.py index aca3e895b..b7cbb6b08 100644 --- a/samples/create_group.py +++ b/samples/create_group.py @@ -40,7 +40,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) + server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): # this code shows 3 different error codes that mean "resource is already in collection" # 409009: group already exists on server diff --git a/samples/create_project.py b/samples/create_project.py index d775902aa..76c76105d 100644 --- a/samples/create_project.py +++ b/samples/create_project.py @@ -49,7 +49,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, http_options={"verify": False}) + server = TSC.Server(args.server) server.use_server_version() with server.auth.sign_in(tableau_auth): diff --git a/samples/create_schedules.py b/samples/create_schedules.py index c23a2eced..df0954b34 100644 --- a/samples/create_schedules.py +++ b/samples/create_schedules.py @@ -39,7 +39,6 @@ def main(): tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=False) - server.add_http_options({"verify": False}) server.use_server_version() with server.auth.sign_in(tableau_auth): # Hourly Schedule diff --git a/samples/create_user.py b/samples/create_user.py index 8b20f069d..1e4f65783 100644 --- a/samples/create_user.py +++ b/samples/create_user.py @@ -57,7 +57,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) + server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): # this code shows 2 different error codes for common mistakes # 400013: Invalid site role diff --git a/samples/export.py b/samples/export.py index 3200d491f..89023b4ed 100644 --- a/samples/export.py +++ b/samples/export.py @@ -54,7 +54,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) + server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): print("Connected") if args.workbook: diff --git a/samples/filter_sort_groups.py b/samples/filter_sort_groups.py index 1694bf0f5..61130de70 100644 --- a/samples/filter_sort_groups.py +++ b/samples/filter_sort_groups.py @@ -47,7 +47,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) + server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): group_name = "SALES NORTHWEST" # Try to create a group named "SALES NORTHWEST" diff --git a/samples/getting_started/1_hello_server.py b/samples/getting_started/1_hello_server.py index 5f8cfa238..c759a534c 100644 --- a/samples/getting_started/1_hello_server.py +++ b/samples/getting_started/1_hello_server.py @@ -12,6 +12,17 @@ def main(): # This is the domain for Tableau's Developer Program server_url = "https://10ax.online.tableau.com" server = TSC.Server(server_url) + + # OPTIONAL, FOR A TEST SERVER ONLY: turn off certificate verification. + # If your test server uses a self-signed certificate, requests fail with + # SSL: CERTIFICATE_VERIFY_FAILED. Turning verification off lets anyone between + # you and the server read or change the traffic, including your credentials, + # so never do this for a production server. Prefer giving TSC the server's + # certificate instead, see + # https://tableau.github.io/server-client-python/docs/sign-in-out#handling-ssl-certificates-for-tableau-server + # To opt in, uncomment the next line: + # server.add_http_options({"verify": False}) + print(f"Connected to {server.server_info.baseurl}") print(f"Server information: {server.server_info}") print("Sign up for a test site at https://www.tableau.com/developer") diff --git a/samples/refresh.py b/samples/refresh.py index 99242fcdb..1b6a14257 100644 --- a/samples/refresh.py +++ b/samples/refresh.py @@ -43,7 +43,7 @@ def main(): incremental = True tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) + server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): if args.resource_type == "workbook": # Get the workbook by its Id to make sure it exists diff --git a/tableauserverclient/server/server.py b/tableauserverclient/server/server.py index 853bdea68..259864fd0 100644 --- a/tableauserverclient/server/server.py +++ b/tableauserverclient/server/server.py @@ -2,7 +2,6 @@ import requests import threading -import urllib3 import ssl import weakref @@ -260,10 +259,8 @@ def __repr__(self): def add_http_options(self, options_dict: dict): try: + options_dict.keys() # reject non-mappings that dict.update would accept, such as lists of pairs self._http_options.update(options_dict) - if "verify" in options_dict.keys() and self._http_options.get("verify") is False: - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - # would be nice if you could turn them back on except Exception as be: # expected errors on invalid input: # 'set' object has no attribute 'keys', 'list' object has no attribute 'keys' diff --git a/test/http/test_http_requests.py b/test/http/test_http_requests.py index 494d458ea..1e708afe4 100644 --- a/test/http/test_http_requests.py +++ b/test/http/test_http_requests.py @@ -1,3 +1,5 @@ +import warnings + import pytest import tableauserverclient as TSC import requests @@ -70,6 +72,13 @@ def test_http_options_skip_ssl_works(): server.add_http_options(http_options) +def test_http_options_skip_ssl_leaves_warning_filters_alone(): + filters_before = list(warnings.filters) + server = TSC.Server("http://fake-url") + server.add_http_options({"verify": False}) + assert warnings.filters == filters_before + + def test_http_options_multiple_options_works(): http_options = {"verify": False, "birdname": "Parrot"} server = TSC.Server("http://fake-url")