I'm running my project on localhost(http://127.0.0.1:5000/) and would be differently on my client server. So I try tried to dynamically get the URL Address but with no avail.
I tried: request.host_url
as showing in this thread. However, it returned
RuntimeError: working outside of request context
Here what I tried to do is run python unittest that need full URL as parameter post(), that's a reason I need it dynamic url.
import json, requests
from flask import request
from .base import *
class TestProvince(BaseTest):
# Test Data
ID = '41'
DESCRIPTION = 'Province Test'
LOCAL_DESCRIPTION = 'Province local Description'
def test_add_record(self):
print "Adding a new record"
url = "http://127.0.0.1:5000/Project/API/Province/" # <-- Here I want it to be dynamic url
payload = {
"Status":"AUTH",
"Curr":"0",
"Inputter":"System",
"Createdon":"2019-05-03",
"Authorizer":"System",
"Authorizeon":"2019-05-03",
"Branch":"HO",
"ID":self.ID,
"Description":self.DESCRIPTION,
"LocalDescription":self.LOCAL_DESCRIPTION
}
headers = {
'Content-Type': "application/json",
'Accept': "application/json"
}
response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
if __name__ == "__main__":
unittest.main()
Any tip for how can I get current URL Address correctly in python? Thanks