I am using soap4r with ruby 1.8.7p358 and I am facing a strange error. I have an endpoint_url, when I browse it, there is no authentication error message. It prints out the response. However, when I create a soap client and try to access the method of the client, it gives me authentication error.
For instatance:
I have a url (say) endpoint_url.com/api/get_name.php?user_name="test"&api_key="test"
This link gives me response like
<response>
<result>
<success>1</success>
</result>
<userspage="1" numberofpages="1" numberofusers="1"><row>Sadiksha</row>
</domains>
</response>
I initialize the rpc driver as
def initialize
#username = "test"
#apikey = "test"
#driver = SOAP::RPC::Driver.new("endpoint_url.com/api/get_name.php", "urn:UserDetails")
end
I have a method in the same file that gets all the statistics of user
def getStats (name)
#driver.add_method('GetDetails', 'name')
user_details = {
'user_name' => #username,
'api_key' => #apikey,
'name' => name
}
result = #driver.GetDetails(user_details)
return result
end
When I run the program it gives me error "Your username & apikey were not recognised!" I have been looking at it for a sometime now. But, I really cannot figure out what might be wrong! Can anyone please let me know what I am doing wrong here!
Related
I'm trying to make SlackBot and if I call him in some public channel it works fine but when I call him (type slash-command) in any direct channel I receive "The server responded with: {'ok': False, 'error': 'channel_not_found'}". In public channels where I've invited my bot it works fine, but if I type "/my-command" in any DM-channel I receive response in separate DM-channel with my bot. I expect to receive these responses in that DM-channel where I type the command.
Here is some part of my code:
if slack_command("/command"):
self.open_quick_actions_message(user_id, channel_id)
return Response(status=status.HTTP_200_OK)
def open_quick_actions_message(self, user, channel):
"""
Opens message with quick actions.
"""
slack_template = ActionsMessage()
message = slack_template.get_quick_actions_payload(user=user)
client.chat_postEphemeral(channel=channel, user=user, **message)
Here are my Event Eubscriptions
Here are my Bot Token Scopes
Can anybody help me to solve this?
I've already solved my problem. Maybe it will help someone in the future. I've sent my payload as the immediate response as it was shown in the docs and the response_type by default is set to ephemeral.
The part of my code looks like this now:
if slack_command("/command"):
res = self.slack_template.get_quick_actions_payload(user_id)
return Response(data=res, status=status.HTTP_200_OK)
else:
res = {"text": "Sorry, slash command didn't match. Please try again."}
return Response(data=res, status=status.HTTP_200_OK)
Also I have an action-button and there I need to receive some response too. For this I used the response_url, here are the docs, and the requests library.
Part of this code is here:
if action.get("action_id", None) == "personal_settings_action":
self.open_personal_settings_message(response_url)
def open_personal_settings_message(self, response_url):
"""
Opens message with personal settings.
"""
message = self.slack_template.get_personal_settings_payload()
response = requests.post(f"{response_url}", data=json.dumps(message))
try:
response.raise_for_status()
except Exception as e:
log.error(f"personal settings message error: {e}")
P. S. It was my first question and first answer on StackOverflow, so don't judge me harshly.
Having a strange issue while trying to use aiohttp/asyncio with Artifactory REST API.
The strange thing is that the below code works perfectly for 'url_2' but permanently fails with aiohttp.client_exceptions.ClientPayloadError: Response payload is not completed for 'url_1'. As you can see, there is absolutely no difference between these URLs.
import aiohttp
import asyncio
user_name = 'username'
user_password = 'password'
url_1 = 'https://someorg.jfrog.io/someorg/api/storage/repo/folder-xxx' # fails
url_2 = 'https://someorg.jfrog.io/someorg/api/storage/repo/folder-yyy' # works
async def fetch(url, user_name, user_password):
async with aiohttp.ClientSession(auth=aiohttp.BasicAuth(user_name, user_password)) as session:
remote_resp = await session.request("GET", url)
return await remote_resp.json()
r = asyncio.run(fetch(url_1, user_name, user_password))
print(r)
I am thinking that this has something to do with chunks, as they state it here: https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientPayloadError
class aiohttp.ClientPayloadError
This exception can only be raised while reading the response payload if one of these errors occurs:
invalid compression
malformed chunked encoding
not enough data that satisfy Content-Length HTTP header.
Literally stuck and have no ideas :(
FYI: duplicated issue to aio-lib at https://github.com/aio-libs/aiohttp/issues/2076
Could anyone point the direction to at least debug and define the root cause?
I wrote some code that gets an access token. When the code runs, a browser displays on the screen which contains the access token.
But when I try to get the access token and log it, a null string is being displayed. Also, I do not know if there is a way to force the browser to close using my code. Right now when I run this code, the browser window opens but I have to click on it to close it.
Could you please let me know what I am doing wrong ?
import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade
import com.eviware.soapui.support.editor.inspectors.auth.TokenType
def project = context.getTestCase().getTestSuite().getProject();
def oAuthProfile = project.getAuthRepository().getEntry("IMAGEN_Profile");
def clientSecret = testRunner.testCase.testSuite.getPropertyValue("Client_Secret")
def clientID = testRunner.testCase.testSuite.getPropertyValue("Client_ID")
oAuthProfile.setClientSecret(clientSecret);
oAuthProfile.setClientID(clientID);
log.info("Client Secret:"+clientSecret)
log.info("Client ID:"+clientID)
// the following code for getting new access token
def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS);
oAuthClientFacade.requestAccessToken(oAuthProfile, true);
def accessToken = oAuthProfile.getAccessToken()
testRunner.testCase.testSuite.setPropertyValue("Auth_Code",accessToken)
log.info("Access Token:"+accessToken)
Unfortunately, the SoapUI documentation is rather terse.
Change your
oAuthClientFacade.requestAccessToken(oAuthProfile, true);
to
oAuthClientFacade.requestAccessToken(oAuthProfile, true, true);
source
we have developed some of the aiohttp server side apis and from that api we am calling one of the python class, where i have done all business logic.
now we want to create a error handling framework for all apis, please give some ideas to implement that framework and i need to do request parameters validations as well, should i consolidate and send back all error at one time or just check one parameter send back the error message to caller.
api look like this:
async def new_user(request):
try:
# happy path where name is set
user = request.query['name']
# Process our new user
print("Creating new user with name: " , user)
response_obj = { 'status' : 'success' }
# return a success json response with status code 200 i.e. 'OK'
return web.Response(text=json.dumps(response_obj), status=200)
except Exception as e:
# Bad path where name is not set
response_obj = { 'status' : 'failed', 'reason': str(e), 'code' : 400 }
# return failed with a status code of 500 i.e. 'Server Error'
return web.Response(text=json.dumps(response_obj), status=400)
If you are using aio-http try to create aiohttp.web.middleware.
https://docs.aiohttp.org/en/stable/web_advanced.html#middlewares
I need to grab a data from XML-RPC web-service.
new XmlSlurper().parse("http://host/service") works fine, but now I have a particular service that requires basic HTTP authentication.
How can I set username and password for parse() method, or modify HTTP headers of the request?
Using http://username:password#host/service doesn't help - I still get java.io.IOException: Server returned HTTP response code: 401 for URL exception.
Thanks
I found this code over here which might help?
Editing this code to your situation, we get:
def addr = "http://host/service"
def authString = "username:password".getBytes().encodeBase64().toString()
def conn = addr.toURL().openConnection()
conn.setRequestProperty( "Authorization", "Basic ${authString}" )
if( conn.responseCode == 200 ) {
def feed = new XmlSlurper().parseText( conn.content.text )
// Work with the xml document
} else {
println "Something bad happened."
println "${conn.responseCode}: ${conn.responseMessage}"
}
This will work for you
Please remember to use this instead of the 'def authString' mentioned above:
def authString = "${usr}:${pwd}".getBytes().encodeBase64().toString()