node.js – How to solve the python 405 POST response

import requests
import json

from request.auth import HTTPBasicAuth
myHeaders = {& # 39; accept & # 39 ;: & # 39; application / json & # 39 ;, & # 39 ;, content-type & # 39 ;: & # 39; application / json & # 39 ;, & # 39; X -Killbill-CreatedBy & # 39 ;: & # 39; demo & # 39 ;, & # 39; authorization & # 39 ;: & # 39; Basic YWRtaW46cGFzc3dvcmQ = & # 39 ;, & # 39; X- Killbill-ApiKey & # 39 ;: & # 39; abcd & # 39;, & # 39; X-Killbill-ApiSecret & # 39;: & # 39; dcba & # 39;}

myData = {& # 39; transactionType & # 39 ;: & # 39; AUTHORIZE & # 39 ;, & # 39; amount & # 39 ;: 23, & # 39; currency & # 39 ;: & # 39; INR & # 39 ;, & # 39; transactionExternalKey & # 39 ;: & # 39; python003 & # 39;}

myParams = {& # 39; paymentMethodId & # 39 ;: & # 39; 810d4eae-4668-4c6a-897c-178c041eb67f & # 39;}

answer = requests.get (
& # 39; http: //192.168.12.80: 8080 / 1.0 / kb / accounts / a6c08c2c-f3eb-456a-a681-6e5262262e94 & # 39 ;,
params = myParams,
headers = myHeaders,
data = json.dumps (myData),
)
print (answer)

rest api: extract the response element from the API and complete it in Gravity Form

I have spent the whole day trying to capture and display the contents of an API call to Zillow in the form from which it was sent using this stack:

WordPress 5.3
GravityForms 2.4.15.6 (paid)
Autofill of gravity form addresses (payment: link to paid add-on)
Forms: third-party integration (free: link to the WordPress plugin page)
Forms: third-party injection results (free: link to the WordPress plugin page)
Zillow GetSearchResults API (free: link to the Zillow API)

After hours of frustration, I finally connected to Zillow and successfully received the answer contained in this file: Link to the third-party integration debug text file that shows the responses.

Now that I have connected, I am supposed to extract XML or JSON and replace / overwrite the content of a field within the origin severity form (or in my case, the confirmation) (visible here: link to the severity form) by following The instructions included here, link to instructions from Third Party Injection Results in GitHub using a syntax that I simply cannot understand, something like:

XML

(env:Envelope/env:Body/ns1:Response/ns1:Resultstatus) => foo
(env:Envelope/env:Body/ns1:Response/ns1:Result) => bar
(env:Envelope/env:Body/ns1:Response/ns1:Description) => baz

or

JSON

(Body/Response/ResultStatus) => foo
(Body/Response/Result) => bar
(Body/Response/Description) => baz

I am trying to extract / display the content of the "estimate" element, at this time, specifically the content of the "quantity" element (once you discover it, you may want to use all the elements within "estimate").

I have tried so many variations without success, I am exhausted. I had to communicate with someone who could know what syntax / format to use.

The successful Zillow XML response, together with the fields that I need to capture, can be seen in the text file here link to the Zillow XML response

I've searched everywhere, but the correct syntax / format information is sparse in this specific topic / add-on.

I would greatly appreciate the guidance of a guru to help me format the correct syntax so I can continue with my life. Hahaha

Thanks in advance.

Use the JSON results of a SharePoint API search response

I am using the SharePoint REST API to do a search. I am withdrawing the results from JSON and read them as follows:

HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(querystring);

endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json; odata=verbose";
endpointRequest.UseDefaultCredentials = true;
HttpWebResponse endpointResponse =(HttpWebResponse)endpointRequest.GetResponse();

Stream webStream = endpointResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
var results = responseReader.ReadToEnd();

This works fine, I can see the results in JSON format. So I created a class from JSON in VS 2017 and here are the classes created from JSON (this was done automatically with File => Paste Special => Paste JSON As Classes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class SharePointRESTResults
    {
        public class Rootobject
        {
            public D d { get; set; }
        }

        public class D
        {
            public Query query { get; set; }
        }

        public class Query
        {
            public __Metadata __metadata { get; set; }
            public int ElapsedTime { get; set; }
            public Primaryqueryresult PrimaryQueryResult { get; set; }
            public Properties1 Properties { get; set; }
            public Secondaryqueryresults SecondaryQueryResults { get; set; }
            public string SpellingSuggestion { get; set; }
            public Triggeredrules TriggeredRules { get; set; }
        }

        public class __Metadata
        {
            public string type { get; set; }
        }

        public class Primaryqueryresult
        {
            public __Metadata1 __metadata { get; set; }
            public Customresults CustomResults { get; set; }
            public string QueryId { get; set; }
            public string QueryRuleId { get; set; }
            public object RefinementResults { get; set; }
            public Relevantresults RelevantResults { get; set; }
            public object SpecialTermResults { get; set; }
        }

        public class __Metadata1
        {
            public string type { get; set; }
        }

        public class Customresults
        {
            public __Metadata2 __metadata { get; set; }
            public object() results { get; set; }
        }

        public class __Metadata2
        {
            public string type { get; set; }
        }

        public class Relevantresults
        {
            public __Metadata3 __metadata { get; set; }
            public object GroupTemplateId { get; set; }
            public object ItemTemplateId { get; set; }
            public Properties Properties { get; set; }
            public object ResultTitle { get; set; }
            public object ResultTitleUrl { get; set; }
            public int RowCount { get; set; }
            public Table Table { get; set; }
            public int TotalRows { get; set; }
            public int TotalRowsIncludingDuplicates { get; set; }
        }

        public class __Metadata3
        {
            public string type { get; set; }
        }

        public class Properties
        {
            public Result() results { get; set; }
        }

        public class Result
        {
            public __Metadata4 __metadata { get; set; }
            public string Key { get; set; }
            public string Value { get; set; }
            public string ValueType { get; set; }
        }

        public class __Metadata4
        {
            public string type { get; set; }
        }

        public class Table
        {
            public __Metadata5 __metadata { get; set; }
            public Rows Rows { get; set; }
        }

        public class __Metadata5
        {
            public string type { get; set; }
        }

        public class Rows
        {
            public Result1() results { get; set; }
        }

        public class Result1
        {
            public __Metadata6 __metadata { get; set; }
            public Cells Cells { get; set; }
        }

        public class __Metadata6
        {
            public string type { get; set; }
        }

        public class Cells
        {
            public Result2() results { get; set; }
        }

        public class Result2
        {
            public __Metadata7 __metadata { get; set; }
            public string Key { get; set; }
            public object Value { get; set; }
            public string ValueType { get; set; }
        }

        public class __Metadata7
        {
            public string type { get; set; }
        }

        public class Properties1
        {
            public Result3() results { get; set; }
        }

        public class Result3
        {
            public __Metadata8 __metadata { get; set; }
            public string Key { get; set; }
            public string Value { get; set; }
            public string ValueType { get; set; }
        }

        public class __Metadata8
        {
            public string type { get; set; }
        }

        public class Secondaryqueryresults
        {
            public __Metadata9 __metadata { get; set; }
            public object() results { get; set; }
        }

        public class __Metadata9
        {
            public string type { get; set; }
        }

        public class Triggeredrules
        {
            public __Metadata10 __metadata { get; set; }
            public object() results { get; set; }
        }

        public class __Metadata10
        {
            public string type { get; set; }
        }

    }
}

So now I am trying to deserialize the results as follows:

 SharePointRESTResults resultX = JsonConvert.DeserializeObject(results());

It seems that it is being serialized, but I am having trouble extracting class properties. I have tried:

var y = resultX.(d).(query).(Primaryqueryresult).(Relevantresults).(Table).(Rows).(results).(0).(Cells).(results).(0).(Key);

to try to get the results but I get "The name & # 39; d & # 39; does not exist in the current context" Has anyone tried to do this? Any help is really appreciated.

8 – Disable page cache for redirect response

I implemented a conditional redirect on my site through an event subscriber and returned a redirect response. It's working but, I think because of the page_cache The module is being cached for anonymous users.

This is basically what I am using to configure the redirect response:

public function checkRedirectStatus(GetResponseEvent $event) {
    if(shouldIRedirect()) {
        $response = new RedirectResponse('/redirect/path');
        $event->setResponse($response);
     }
}

The above is cached whether it returns true or not unless you add Drupal::service('page_cache_kill_switch')->trigger();.

Since this is a page with a lot of traffic, I worry about ignoring the cache for anonymous users. Are there other options I don't know?

If this is in the REQUEST kernel event, how far is it page_cache_kill_switch?

Thanks for your help!

Python: best practice to ensure the connection and response of external API results

I have this code in python (using django firmware) that connects to an external API and updates some values ​​in that service. Each step depends on the previous step (for step 2 to work, step 1 must return True and so on that include a valid connection to the API). How can I make sure that all these steps are carried out at the same time? If a single step fails, how can I go back and execute them all at once in another attempt? Here is the code. Keep in mind that each class method does something in that external service.

# 1. add new value to account
if cls.add_balance(subscription_code, increase_amount):
# 2. set new base balance
if cls.set_topup_reset_action(
        subscription_code,
        new_base_balance,
):
    # 3. renew filters
    new_base_balance_20_percent = math.floor((Decimal(
        new_base_balance) * Decimal(20)) / Decimal(100))
    if cls.set_filter_80_percent(
            subscription_code,
            new_base_balance_20_percent,
    ) and cls.set_filter_100_percent(
        subscription_code,
    ):
        # 4. renew thresholds
        if cls.set_threshold_profile_80_percent(
                subscription_code,
        ) and cls.set_threshold_profile_100_percent(
            subscription_code,
        ):
            return True
return False

Alternative routes for the incident response approach other than Windows Event Viewer?

I am currently developing an Incident Response Plan for a computer that has been hacked (no malware installed, just a system hack). My plan is to look through the Windows Event Viewer to try to detect any unusual behavior on the machine.

However, if an attacker has changed the contents of the log file or altered the time, what are the alternative routes to develop an IRP other than Windows Event Viewer?

Object-oriented: classes to represent an HTTP request and response in C ++

I am writing an HTTP message encoder / decoder. In my decoder, I analyze http messages in http_request or http_response. In my encoder I encode one of these classes.

Representing the messages is the easy part, but I am sure that I have made some mistakes. Please review and let me know what could be improved.

Some questions:
1. I make the http_message base class available, which is probably not ideal. Should I hide this in a different header? Or hide in another way? any ideas?
2. I don't think I need copy and assignment operators because I am not using pointers. Is that correct?
3. Are the tests enough?

Header file, http_message.hpp:

#ifndef HTTP_MESSAGE_HPP_
#define HTTP_MESSAGE_HPP_

#include 
#include 
#include 

class http_message {
public:
    http_message();
    void set_version(int major, int minor);
    const std::string get_version() const;
    size_t get_body_length() const;
    void body(const std::string& data);
    std::string body() const;
    void add_header(const std::string& key, const std::string& value);
    const std::string get_header_value(const std::string& key) const;

    typedef const std::unordered_map::const_iterator const_iterator;
    const_iterator begin() const { return headers_.begin(); }
    const_iterator end() const { return headers_.end(); }

protected:
    void set_body_length(size_t length);
    std::unordered_map headers_;
    std::string body_;
    std::string version_;
};

class http_response : public http_message {
public:
    unsigned status = 0;
};

class http_request : public http_message {
public:
    std::string url;
    std::string method;
    std::string query;
};

std::ostream& operator<<(std::ostream& os, const http_request& request);
std::ostream& operator<<(std::ostream& os, const http_response& request);

#endif // HTTP_MESSAGE_HPP_

http_message.cpp:

#include 

#include "http_message.hpp"

static const std::string content_length_string("Content-Length");

static bool case_insensitive_match(std::string s1, std::string s2) {
    // Convert complete given string to lower case
    std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    // Convert complete given sub-string to lower case
    std::transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
    return s1.find(s2) == 0;  // must be found at start of string
}

http_message::http_message() : version_("HTTP/1.1") { 
    headers_(content_length_string) = "0";
}

void http_message::set_version(int major, int minor) {
    version_ = "HTTP/" + std::to_string(major) + '.' + std::to_string(minor);
}

size_t http_message::get_body_length() const {
    return body_.length();
}

void http_message::set_body_length(size_t length) {
    headers_(content_length_string) = std::to_string(length);
}

void http_message::add_header(const std::string& key, const std::string& value) {

    // check for Content-Length - override whatever length is set based on body length
    // Fix header key as Content-Length to ease checking header
    if (case_insensitive_match(key, content_length_string)) {
        headers_(content_length_string) = std::to_string(body_.length());
    }
    else {
        headers_(key) = value;
    }
}

const std::string http_message::get_version() const {
    return version_;
}

void http_message::body(const std::string& data) {
    body_ = data;
    headers_(content_length_string) = std::to_string(body_.length());
}

std::string http_message::body() const {
    return body_;
}

const std::string http_message::get_header_value(const std::string& key) const {
    const auto it = headers_.find(key);
    return it != headers_.end() ? it->second : "";
}

std::ostream& operator<<(std::ostream& os, const http_request& request) {
    os << "Method=" << request.method << std::endl;
    os << "url: " << request.url << std::endl;
    if (request.get_body_length() > 0) {
        os << "body: " << request.body() << std::endl;
    }
    if (!request.query.empty()) {
        os << "query: " << request.query << std::endl;
    }

    // print all headers
    for (const auto& header : request) {
        os << header.first << ": " << header.second << std::endl;
    }
    return os;
}

std::ostream& operator<<(std::ostream& os, const http_response& response) {
    os << "Status=" << response.status << std::endl;
    if (response.get_body_length() > 0) {
        os << "body: " << response.body() << std::endl;
    }

    // print all headers
    for (const auto& header : response) {
        os << header.first << ": " << header.second << std::endl;
    }
    return os;
}

Some tests: test.cpp:

#include "gtest/gtest.h"

#include "http_message.hpp"

TEST(http_message_tests, message_length_calculated_correctly) {
    http_request rq;
    rq.add_header("Content-Type", "text/plain");
    rq.body("Text message");
    EXPECT_EQ(rq.get_header_value("Content-Length"), "12");
    EXPECT_EQ(rq.get_body_length(), 12);
}

TEST(http_message_tests, message_length_with_no_body_zero) {
    http_request rq;
    rq.add_header("Content-Type", "text/plain");
    EXPECT_EQ(rq.get_header_value("Content-Length"), "0");
    EXPECT_EQ(rq.get_body_length(), 0);
}

TEST(http_message_tests, message_without_version_set_defaults_to_http_v1_1) {
    http_request rq;
    EXPECT_EQ(rq.get_version(), "HTTP/1.1");
}

TEST(http_message_tests, message_version_correctly_set) {
    http_request rq;
    rq.set_version(1, 0);
    EXPECT_EQ(rq.get_version(), "HTTP/1.0");
}

TEST(http_message_tests, message_header_correctly_set) {
    http_request rq;
    rq.add_header("Content-Type", "text/plain");
    EXPECT_EQ(rq.get_header_value("Content-Type"), "text/plain");
}

TEST(http_message_tests, http_response_correctly_default_initialised) {
    http_response rs;
    EXPECT_EQ(rs.get_header_value("Content-Length"), "0");
    EXPECT_EQ(rs.status, 0u);
    EXPECT_EQ(rs.get_version(), "HTTP/1.1");
}

TEST(http_message_tests, http_request_correctly_default_initialised) {
    http_request rq;
    EXPECT_EQ(rq.get_header_value("Content-Length"), "0");
    EXPECT_EQ(rq.get_version(), "HTTP/1.1");
    EXPECT_EQ(rq.get_body_length(), 0);
}

TEST(http_message_tests, http_response_headers_added_correctly) {
    http_response rs;
    EXPECT_EQ(rs.get_header_value("Content-Length"), "0");
    EXPECT_EQ(rs.status, 0u);
    EXPECT_EQ(rs.get_version(), "HTTP/1.1");
}

TEST(http_message_tests, http_request_headers_added_correctly) {
    http_request rq;
    rq.method = "POST";
    rq.url = "/welcome.php";
    rq.set_version(1, 0);
    rq.add_header("Host", "www.iteloffice.com");
    rq.add_header("Content-Type", "application/x-www-form-urlencoded");
    std::string body("name=Joe+Bloggs&email=joe%40bloggs.com");
    rq.body(body);

    EXPECT_EQ(rq.url, "/welcome.php");
    EXPECT_EQ(rq.get_version(), "HTTP/1.0");
    EXPECT_EQ(rq.method, "POST");
    EXPECT_EQ(rq.query, "");
    EXPECT_EQ(rq.get_header_value("Content-Length"), std::to_string(body.length()));
    EXPECT_EQ(rq.get_header_value("Host"), "www.iteloffice.com");
    EXPECT_EQ(rq.get_header_value("Content-Type"), "application/x-www-form-urlencoded");
    EXPECT_EQ(rq.body(), body);
}

2d – Problem with diagonal collision response using PyGame

So I have had this problem during the last few days and it has frustrated me a lot. What I am trying to do is resolve collisions with custom hitboxes in PyGame and it looks like this:

enter the description of the image here

Everything works fine until I collide with something diagonally, then a strange error appears in which the character suddenly teleports to the opposite side of the axis with which I am colliding, like this:

https://gyazo.com/62c53cc4f3a944c317a951c0f8ae14ea

I read a lot about this on the last day and, from what I've deduced, does it have to do with the fact that I don't solve the x and y axes independently? perhaps?

If I have a print ("x") and print ("y") statement in their respective code, I get this when I hit something on the "y" axis:

enter the description of the image here

The mistake seems to come from that "x" something random in the middle there. The code resolves a collision as if the character were colliding with something on the "x" axis when it was actually the "y" axis. It is worth nothing than this ONLY It happens when I collide diagonally with the last axis I verify (and in this case). So I guess that's my question really, why does this happen?

Here is my collision management code:

def collide(self, direction):

    hits = pg.sprite.spritecollide(self, all_sprites_wall, False, rectconverter)
    if direction == "x":
        if hits:
            print("x")
            if self.vx > 0:
                hits(0).update()
                self.x = hits(0).hitboxrect.left - self.rect.width - camera.camera.x
                self.hitboxrect.right = hits(0).hitboxrect.left
            if self.vx < 0:
                self.x = hits(0).hitboxrect.right - self.rect.width + self.hitboxrect.width - camera.camera.x
                self.hitboxrect.left = hits(0).hitboxrect.right
            self.rect.x = self.x

    if direction == "y":
        if hits:
            print("y")
            if self.vy > 0:
                self.y = hits(0).hitboxrect.top - self.rect.height - camera.camera.y
                self.hitboxrect.bottom = hits(0).hitboxrect.top
            if self.vy < 0:
                self.y = hits(0).hitboxrect.bottom - self.rect.height + self.hitboxrect.height - camera.camera.y
                self.hitboxrect.top = hits(0).hitboxrect.bottom
            self.rect.y = self.y

And here is the player update function:

def update(self):
    self.move()

    self.hitboxrect.y = self.y + camera.camera.y + self.rect.height - self.hitboxrect.height
    self.rect.y = self.y
    self.collide("y")
    self.hitboxrect.x = self.x + camera.camera.x
    self.rect.x = self.x
    self.collide("x")

I think the problem is somewhere in this code, but if you believe otherwise, do not hesitate to say so and I will gladly add more code!

Assetbundle loading show No data received in response at Unity 2019.2.9

Recently I have converted my Unity 2019.1.0 project into Unity 2019.2.9 and it is a WebGL project. In the project I am using the asset package and here is the snippet to load the package:

 IEnumerator DependancyAssetBundleLoader()
    {

        www = UnityWebRequestAssetBundle.GetAssetBundle(bundleURLForDependency);
       // www.chunkedTransfer = false;

        yield return www.SendWebRequest();
        AssetBundle bundleDependancy = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;

        if (www.error != null)
        {

            //Debug.LogError("assetBundleURL : " + bundleURLForDependency);
            Debug.LogError("response code : " + www.responseCode);

            Debug.LogError("www error : " + www.error);
            www.Dispose();
            www = null;
            yield break;

        }
    }

I don't know what went wrong with the asset package load and now I receive this error:

He did not receive data in response

I registered the response code and it is 0.

8 – webform ajax callback response does not update the text, is something missing?

The following code works inside hook_form_alter. The description and price update of the database, as desired, in form_alter. I moved the code to the callback and now it will not return / update the values. I use a button to call ajax callback. The throbber shows and then there is no change.

    $form('elements')('billing')('desc01')('#prefix') = '
'; $form('elements')('billing')('desc01')('#suffix') = '
';

and callback

function srvform_items_callback(array &$form, FormStateInterface $form_state) {
    $lkuppart='';
    $lkupok='yes';
    $node_storage = Drupal::entityTypeManager()->getStorage('node');
    $lkuppart=$form('elements')('billing')('itemflex01')('part01')('#default_value');
    if (!empty($lkuppart)) {
        $query = Drupal::entityQuery('node') ->condition('type', 'parts') ->condition('title', $lkuppart);
        $nids = $query->execute();
        $lkupnodes = $node_storage->loadMultiple($nids);
        foreach ($lkupnodes as $nodecnt) {
            $lkuptitle=$nodecnt->title->value;
        }
        if ($lkuptitle <> $lkuppart) {
            $lkupok='false';
        } else {
            $form('elements')('billing')('itemflex01')('price01')('#default_value')=$nodecnt->field_list_price->value;
            $form('elements')('billing')('desc01')('#default_value')=$nodecnt->body->value;
        }
        $lkuptitle='';
    }
    $renderer = Drupal::service('renderer');
    $response = new AjaxResponse();
    $response->addCommand(new ReplaceCommand('#ajax-price01', $renderer->render($form('elements')('billing')('itemflex01')('price01'))));
    $response->addCommand(new ReplaceCommand('#ajax-desc01', $renderer->render($form('elements')('billing')('desc01'))));
    return $response;

Is it simply a bad / obsolete command that I am using?