Skip to content

Commit 4ac02bd

Browse files
Spec 26859: Build content reporting
-- Change get/post to use Requests instead of Session -- Change wiki url construction to use Requests instead of string concatenation
1 parent 3357dcd commit 4ac02bd

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

labkey/unsupported/messageboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"""
5050

5151
from labkey.utils import build_url, handle_response
52+
import requests
5253
from requests.exceptions import SSLError
5354

5455

@@ -91,7 +92,7 @@ def postMessage(server_context, messageTitle, messageBody, renderAs, container_p
9192
data = None
9293

9394
try:
94-
message_response = session.post(message_url, message_data, headers=None) # seems to be happy with Python dict directly
95+
message_response = requests.post(message_url, message_data, headers=None) # seems to be happy with Python dict directly
9596
except SSLError as e:
9697
print("There was problem while attempting to submit the message to " + str(e.geturl()) + ". The HTTP response code was " + str(e.getcode()))
9798
print("The HTTP client error was: "+ format(e))

labkey/unsupported/wiki.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
import json
4949
from labkey.utils import build_url, handle_response
50+
import requests
5051
from requests.exceptions import SSLError
5152

5253
def updateWiki(server_context, wikiName, wikiBody, container_path=None):
@@ -86,22 +87,21 @@ def updateWiki(server_context, wikiName, wikiBody, container_path=None):
8687

8788
# Build the URL for reading the wiki page
8889
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}
9391
headers = {
9492
'Content-type': 'application/json'
9593
}
9694

95+
data = None
96+
9797
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)
9999
except SSLError as e:
100100
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()))
101101
print("The HTTP client error was: "+ format(e))
102102
return(1) # TODO: this is incorrect, should return 'success'/'error' properly like the docs say
103103

104-
data = read_response.text;
104+
data = read_response.text
105105

106106
# Search HTML response for required information on wiki. This is stored in the javascript
107107
# variable named
@@ -136,19 +136,17 @@ def updateWiki(server_context, wikiName, wikiBody, container_path=None):
136136

137137
# Build the URL for updating the wiki page
138138
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+
}
140142
data = None
141143

142144
# Update wikiVars to use the new wiki content.
143145
wikiVars['name'] = wikiName
144146
wikiVars['body'] = wikiBody
145147

146-
headers = {
147-
'Content-type': 'application/json'
148-
}
149-
150148
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)
152150
data = handle_response(response)
153151
except SSLError as e:
154152
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

Comments
 (0)