|
47 | 47 |
|
48 | 48 | import json |
49 | 49 | from labkey.utils import build_url, handle_response |
| 50 | +import requests |
50 | 51 | from requests.exceptions import SSLError |
51 | 52 |
|
52 | 53 | def updateWiki(server_context, wikiName, wikiBody, container_path=None): |
@@ -86,22 +87,21 @@ def updateWiki(server_context, wikiName, wikiBody, container_path=None): |
86 | 87 |
|
87 | 88 | # Build the URL for reading the wiki page |
88 | 89 | read_wiki_url = build_url(server_context, 'wiki', 'editWiki.api', container_path=container_path) |
89 | | - read_wiki_url = read_wiki_url + '?name=' + wikiName # editWiki action only takes URL parameters, not JSON (JSON is not bound to form) |
90 | | - session = server_context['session'] |
91 | | - data = None |
92 | | - |
| 90 | + payload = {'name': wikiName} |
93 | 91 | headers = { |
94 | 92 | 'Content-type': 'application/json' |
95 | 93 | } |
96 | 94 |
|
| 95 | + data = None |
| 96 | + |
97 | 97 | try: |
98 | | - read_response = session.get(read_wiki_url, headers=headers) |
| 98 | + read_response = requests.get(read_wiki_url, params=payload, headers=headers) # editWiki action only takes URL parameters, not JSON (JSON is not bound to form) |
99 | 99 | except SSLError as e: |
100 | 100 | print("There was a problem while attempting to submit the read for the wiki page " + str(wikiName) + " via the URL " + str(e.geturl()) + ". The HTTP response code was " + str(e.getcode())) |
101 | 101 | print("The HTTP client error was: "+ format(e)) |
102 | 102 | return(1) # TODO: this is incorrect, should return 'success'/'error' properly like the docs say |
103 | 103 |
|
104 | | - data = read_response.text; |
| 104 | + data = read_response.text |
105 | 105 |
|
106 | 106 | # Search HTML response for required information on wiki. This is stored in the javascript |
107 | 107 | # variable named |
@@ -136,19 +136,17 @@ def updateWiki(server_context, wikiName, wikiBody, container_path=None): |
136 | 136 |
|
137 | 137 | # Build the URL for updating the wiki page |
138 | 138 | update_wiki_url = build_url(server_context, 'wiki', 'saveWiki.api', container_path=container_path) |
139 | | - session = server_context['session'] |
| 139 | + headers = { |
| 140 | + 'Content-type': 'application/json' |
| 141 | + } |
140 | 142 | data = None |
141 | 143 |
|
142 | 144 | # Update wikiVars to use the new wiki content. |
143 | 145 | wikiVars['name'] = wikiName |
144 | 146 | wikiVars['body'] = wikiBody |
145 | 147 |
|
146 | | - headers = { |
147 | | - 'Content-type': 'application/json' |
148 | | - } |
149 | | - |
150 | 148 | try: |
151 | | - response = session.post(update_wiki_url, data=json.dumps(wikiVars, sort_keys=True), headers=headers) |
| 149 | + response = requests.post(update_wiki_url, data=json.dumps(wikiVars, sort_keys=True), headers=headers) |
152 | 150 | data = handle_response(response) |
153 | 151 | except SSLError as e: |
154 | 152 | print("There was a problem while attempting to submit the read for the wiki page '" + str(wikiName) + "' via the URL " + str(e.geturl()) + ". The HTTP response code was " + str(e.getcode())) |
|
0 commit comments