How to pass credentials to RESTinstance POST Request in robot framework?
Python Code (Working fine):
credentials = ("key","token")
verify = False
if not verify:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
response = requests.post(url, auth=credentials, data=json.dumps(payload), headers={'content-type': 'application/json'}, verify=verify)
status = response.status_code
Robot Framework Code:
I would like to duplicate same API testing in robot framework but i am stuck how to pass credentials to the RESTinstance POST method
*** Settings ***
Library REST url=https://testhost.com ssl_verify=${verify}
*** Variables ***
header = {"content-type": "application/json"}
*** Test Cases ***
Test Task
POST endpoint=/api/something body=${payload} headers=${header}
Output response status
ERROR RESPONSE STATUS - 401
python robotframework
add a comment |
Python Code (Working fine):
credentials = ("key","token")
verify = False
if not verify:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
response = requests.post(url, auth=credentials, data=json.dumps(payload), headers={'content-type': 'application/json'}, verify=verify)
status = response.status_code
Robot Framework Code:
I would like to duplicate same API testing in robot framework but i am stuck how to pass credentials to the RESTinstance POST method
*** Settings ***
Library REST url=https://testhost.com ssl_verify=${verify}
*** Variables ***
header = {"content-type": "application/json"}
*** Test Cases ***
Test Task
POST endpoint=/api/something body=${payload} headers=${header}
Output response status
ERROR RESPONSE STATUS - 401
python robotframework
add a comment |
Python Code (Working fine):
credentials = ("key","token")
verify = False
if not verify:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
response = requests.post(url, auth=credentials, data=json.dumps(payload), headers={'content-type': 'application/json'}, verify=verify)
status = response.status_code
Robot Framework Code:
I would like to duplicate same API testing in robot framework but i am stuck how to pass credentials to the RESTinstance POST method
*** Settings ***
Library REST url=https://testhost.com ssl_verify=${verify}
*** Variables ***
header = {"content-type": "application/json"}
*** Test Cases ***
Test Task
POST endpoint=/api/something body=${payload} headers=${header}
Output response status
ERROR RESPONSE STATUS - 401
python robotframework
Python Code (Working fine):
credentials = ("key","token")
verify = False
if not verify:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
response = requests.post(url, auth=credentials, data=json.dumps(payload), headers={'content-type': 'application/json'}, verify=verify)
status = response.status_code
Robot Framework Code:
I would like to duplicate same API testing in robot framework but i am stuck how to pass credentials to the RESTinstance POST method
*** Settings ***
Library REST url=https://testhost.com ssl_verify=${verify}
*** Variables ***
header = {"content-type": "application/json"}
*** Test Cases ***
Test Task
POST endpoint=/api/something body=${payload} headers=${header}
Output response status
ERROR RESPONSE STATUS - 401
python robotframework
python robotframework
edited Nov 14 '18 at 4:41
Todor Minakov
6,0142136
6,0142136
asked Nov 12 '18 at 15:49
Sathish ChinnasamySathish Chinnasamy
285
285
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The auth
argument in requests post()
method is just a shortcut to http basic authentication.
And it on the other hand is a very simple (hence - basic) one - a header with name "Authorization", with value "Basic b64creds", where b64creds is base64 encoded form of the "user:password" string.
So the flow is quite simple - encode the credentials, and add them as a header. There is only one caveat - python's base64
module works with bytes, where the strings in Robotframework/python3 are unicode, so they have to be converted.
${user}= Set Variable username
${pass}= Set Variable the_password
# this kyword is in the Strings library
${userpass}= Convert To Bytes ${user}:${pass} # this is the combined string will be base64 encode
${userpass}= Evaluate base64.b64encode($userpass) base64
# add the new Authorization header
Set To Dictionary ${headers} Authorization Basic ${userpass}
# and send the request with the header in:
POST endpoint=/api/something body=${payload} headers=${header}
1
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265635%2fhow-to-pass-credentials-to-restinstance-post-request-in-robot-framework%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The auth
argument in requests post()
method is just a shortcut to http basic authentication.
And it on the other hand is a very simple (hence - basic) one - a header with name "Authorization", with value "Basic b64creds", where b64creds is base64 encoded form of the "user:password" string.
So the flow is quite simple - encode the credentials, and add them as a header. There is only one caveat - python's base64
module works with bytes, where the strings in Robotframework/python3 are unicode, so they have to be converted.
${user}= Set Variable username
${pass}= Set Variable the_password
# this kyword is in the Strings library
${userpass}= Convert To Bytes ${user}:${pass} # this is the combined string will be base64 encode
${userpass}= Evaluate base64.b64encode($userpass) base64
# add the new Authorization header
Set To Dictionary ${headers} Authorization Basic ${userpass}
# and send the request with the header in:
POST endpoint=/api/something body=${payload} headers=${header}
1
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
add a comment |
The auth
argument in requests post()
method is just a shortcut to http basic authentication.
And it on the other hand is a very simple (hence - basic) one - a header with name "Authorization", with value "Basic b64creds", where b64creds is base64 encoded form of the "user:password" string.
So the flow is quite simple - encode the credentials, and add them as a header. There is only one caveat - python's base64
module works with bytes, where the strings in Robotframework/python3 are unicode, so they have to be converted.
${user}= Set Variable username
${pass}= Set Variable the_password
# this kyword is in the Strings library
${userpass}= Convert To Bytes ${user}:${pass} # this is the combined string will be base64 encode
${userpass}= Evaluate base64.b64encode($userpass) base64
# add the new Authorization header
Set To Dictionary ${headers} Authorization Basic ${userpass}
# and send the request with the header in:
POST endpoint=/api/something body=${payload} headers=${header}
1
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
add a comment |
The auth
argument in requests post()
method is just a shortcut to http basic authentication.
And it on the other hand is a very simple (hence - basic) one - a header with name "Authorization", with value "Basic b64creds", where b64creds is base64 encoded form of the "user:password" string.
So the flow is quite simple - encode the credentials, and add them as a header. There is only one caveat - python's base64
module works with bytes, where the strings in Robotframework/python3 are unicode, so they have to be converted.
${user}= Set Variable username
${pass}= Set Variable the_password
# this kyword is in the Strings library
${userpass}= Convert To Bytes ${user}:${pass} # this is the combined string will be base64 encode
${userpass}= Evaluate base64.b64encode($userpass) base64
# add the new Authorization header
Set To Dictionary ${headers} Authorization Basic ${userpass}
# and send the request with the header in:
POST endpoint=/api/something body=${payload} headers=${header}
The auth
argument in requests post()
method is just a shortcut to http basic authentication.
And it on the other hand is a very simple (hence - basic) one - a header with name "Authorization", with value "Basic b64creds", where b64creds is base64 encoded form of the "user:password" string.
So the flow is quite simple - encode the credentials, and add them as a header. There is only one caveat - python's base64
module works with bytes, where the strings in Robotframework/python3 are unicode, so they have to be converted.
${user}= Set Variable username
${pass}= Set Variable the_password
# this kyword is in the Strings library
${userpass}= Convert To Bytes ${user}:${pass} # this is the combined string will be base64 encode
${userpass}= Evaluate base64.b64encode($userpass) base64
# add the new Authorization header
Set To Dictionary ${headers} Authorization Basic ${userpass}
# and send the request with the header in:
POST endpoint=/api/something body=${payload} headers=${header}
edited Nov 15 '18 at 5:30
answered Nov 12 '18 at 20:11
Todor MinakovTodor Minakov
6,0142136
6,0142136
1
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
add a comment |
1
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
1
1
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
Wowww its working like a monster.. thanks a lot Todor..
– Sathish Chinnasamy
Nov 13 '18 at 4:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265635%2fhow-to-pass-credentials-to-restinstance-post-request-in-robot-framework%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown