I have a dataframe with many rows and columns of the form (this is an oversimplified dataframe):
id dur proto service state attack_cat label
0 1 0.121478 tcp dns FIN Normal 0
1 2 4.287901 udp ftp INT Exploits 1
I would like to write all the rows of this dataframe as json items, like for example, for the first row:
{"type": "event",
"subtype": "",
"datatype": "Instance",
"domain": "Cyber",
"created": str(datetime.datetime.now()),
"details": {id: 1,
dur: 0.121478,
proto: tcp,
service: dns,
state: FIN,
attack_cat: Normal,
label:0}
}
I tried to do something like:
{"type": "event",
"subtype": "",
"datatype": "Instance",
"domain": "Cyber",
"created": str(datetime.datetime.now()),
"details": dataframe.loc[i].to_dict()
}
and do a for loop through all the rows, but it gives me the error
TypeError: unhashable type: 'dict'
There are actually two problems, as far as I can see.
Generally, a python dictionary can be the value of a dictionary. For example,
dict = {
"first_name": "robert",
"last_name": "ren",
"hist": {"today": 1, "yesterday": 2}
}
The value of hist is a dict. This means, that from this perspective your code seems to be ok. However, a dictionary can not be the key, nor can you nest one dict in another one. For example,
{{}}
gives you the following error
TypeError: unhashable type: 'dict'
If you want to solve this problem, I recommend that you print out each line as you create the dicts to see where it breaks. That said, I guess that "details": dataframe.loc[i].to_dict() causes you the trouble.
Second, your first dict is invalid as the keys are not strings. This should be
{
"type": "event",
"subtype": "",
"datatype": "Instance",
"domain": "Cyber",
"created": str(datetime.datetime.now()),
"details": {
"id": 1,
"dur": 0.121478,
"proto": tcp,
"service": dns,
"state": FIN,
"attack_cat": Normal,
"label": 0
}
}
Assuming that the variables are defined variables.
EDIT
The following code works on my machine.
import pandas as pd
df = pd.DataFrame({
"id": [1],
"dur": [0.12],
"proto": ["tcp"],
"service": ["dns"],
"state": ["FIN"],
"attack_cat": ["Normal"],
"label": [0]
})
row_list_as_dict = []
for idx, row in df.iterrows():
row_list_as_dict.append({
"type": "event",
"subtype": "",
"datatype": "Instance",
"domain": "Cyber",
"details": {
'id': row["id"],
'dur': row["dur"],
'proto': row["proto"],
'service': row["service"],
'state': row["state"],
'attack_cat': row["attack_cat"],
'label': row["label"]
}
})
row_list_as_dict
Related
Hello i try to figure out how to encode normal rpc calls in an raw transaction.
Till now my problem is that i dont know what the hex must contain as string.
f.e.
rpc command: "method: 'compositeswap' {'from':'MyAddress','tokenFrom':'MyToken1','amountFrom':'0.001','to':'Address','tokenTo':'Token2','maxPrice':'0.01'}"
There seems to be OP-Codes to exists like OP_DEFI_TX_COMPOSITE_SWAP
how does the chain knows to execute an operation with params?
i tried to figure it out by trying to decode an actual transaction from the test wallet:
from the part
"scriptPubKey": {
"asm": "OP_RETURN 446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000",
"hex": "6a4c50446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000",
"type": "nulldata"
},
of
{
"txid": "9a98d693d4c5107647131ee1bb7a5b0cce0fcdbe390c9609a71f4b71157e39dc",
"hash": "a18a6fd4abf0ba1885febcf37a333b1d1f34b4de954f13538a6619b1d7b20042",
"version": 4,
"size": 309,
"vsize": 228,
"weight": 909,
"locktime": 0,
"vin": [
{
"txid": "9e1140197138ba5e247ab3b3f1f4881bf7be624a939073d9795242caf3634409",
"vout": 1,
"scriptSig": {
"asm": "0014451be7ab94ccd7eff0a33ab8fe997a75c62eb7dd",
"hex": "160014451be7ab94ccd7eff0a33ab8fe997a75c62eb7dd"
},
"txinwitness": [
"30440220552d8aa4e129f566bfe083b780e1dcf67a3ca0176e07407912451371f597bc620220698c6ac483e021b78c7d7bf42e14f1c619618d1941cf12fec7cf8302ece6d3ae01",
"03c7d2dbe5ee429de5d88e8594cda6ceb84268ebbf9d0b16b33664e999307f33e8"
],
"sequence": 4294967295
}
],
"vout": [
{
"value": 0,
"n": 0,
"scriptPubKey": {
"asm": "OP_RETURN 446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000",
"hex": "6a4c50446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000",
"type": "nulldata"
},
"tokenId": 0
},
{
"value": 183.03901748,
"n": 1,
"scriptPubKey": {
"asm": "OP_HASH160 721d5b1c58d38af7b6797b385b6ac291b002f88c OP_EQUAL",
"hex": "a914721d5b1c58d38af7b6797b385b6ac291b002f88c87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"tgfbETCK2kYyvsnHbS41v9aicQzAXLsz9B"
]
},
"tokenId": 0
}
]
}
the
OP_RETURN 446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000
cant be decoded sucessfully back into a string.
does s.o know what kind of encoding it is?
tried
bytess=bytes.fromhex("446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000")
print(bytess.decode("latin-1"))
but only get
INFO (MainThread) 14.05.2022 22:02:39 DfTxi©r
INFO (MainThread) 14.05.2022 22:02:39 [
INFO (MainThread) 14.05.2022 22:02:39 XÓŠ÷¶y{8[j‘°øŒ‡ áõ ©r
You can't just decode the string after the OP Code. It is a concatenation of several input parameters depending on the function.
In your example
6a4c50446654786917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000
6a is OP_RETURN
4c50 is Number of bytes following (in HEX)
44665478 is "DfTx" in HEX
6917a914721d5b1c58d38af7b6797b385b6ac291b002f88c870000e1f5050000000017a914721d5b1c58d38af7b6797b385b6ac291b002f88c870b0000000000000000c74e71050000000000 = the parameters from your json. For your address you need Base58 (in this case) or Bech32 encoding to get the hex (some backward engineering necessary).
The part with lots of zeros is the amount/maxPrice.
The tokens are inserted by their IDs not the name.
I am thinking about writing a guide. So far, I am afraid you have to do some backward engineering. Hope this helps a little bit
I have the issue when creating or updating the Quote. I can not set TrackingCategory options for line items. I request api like document but it not success.
The Tracking Category I have
tracking category
Here is my expected:
my expected
Please help me
Thanks you
Here is format payload for lineItems
"LineItems": [
{
"AccountCode": "200",
"Description": "Development work - developer onsite per day",
"UnitAmount": 650.0000,
"DiscountRate": 10.00,
"LineAmount": 585.00,
"ItemCode": "DevD",
"Quantity": 1.0000,
"TaxAmount": 58.50,
"TaxType": "OUTPUT",
"Tracking": [
{
"Name": "Location",
"Option": "Foo Bar"
}
]
}
],
I'm using HERE Places API.
Firstly I'm doing a search.
For Example this query :
https://places.cit.api.here.com/places/v1/discover/search?q=Test&at=35.6111,-97.5467&r=500&size=1&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid&pretty
According to this documentation (Link) If I add show_refs=pvid to query string, in result I will get external id which I can use to query lookup endpoint.
But in result I get next response :
{
"results": {
"next": "https://places.cit.api.here.com/places/v1/discover/search;context=Zmxvdy1pZD1hY2ExNzk3NC0zYzg3LTU5NzQtYmZkMC04YjAzMDZlYWIzMWJfMTUwNjA3NjMzMTYyMl83NDY3XzM4NTAmb2Zmc2V0PTEmc2l6ZT0x?at=35.6111%2C-97.5467&q=Test&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"items": [
{
"position": [
35.60369,
-97.51761
],
"distance": 2756,
"title": "Southwest Test & Balance",
"averageRating": 0,
"category": {
"id": "business-services",
"title": "Business & Services",
"href": "https://places.cit.api.here.com/places/v1/categories/places/business-services?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/02.icon",
"vicinity": "200 NW 132nd St<br/>Oklahoma City, OK 73114",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD1hY2ExNzk3NC0zYzg3LTU5NzQtYmZkMC04YjAzMDZlYWIzMWJfMTUwNjA3NjMzMTYyMl83NDY3XzM4NTAmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"id": "8403fv6k-d1b2fde0616e0326e321a54b88cd9f53",
"authoritative": true
}
]
},
"search": {
"context": {
"location": {
"position": [
35.6111,
-97.5467
],
"address": {
"text": "Oklahoma City, OK 73134<br/>USA",
"postalCode": "73134",
"city": "Oklahoma City",
"county": "Oklahoma",
"stateCode": "OK",
"country": "United States",
"countryCode": "USA"
}
},
"type": "urn:nlp-types:place",
"href": "https://places.cit.api.here.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPU9rbGFob21hK0NpdHk7bGF0PTM1LjYxMTE7bG9uPS05Ny41NDY3O2NpdHk9T2tsYWhvbWErQ2l0eTtwb3N0YWxDb2RlPTczMTM0O2NvdW50cnk9VVNBO3N0YXRlQ29kZT1PSztjb3VudHk9T2tsYWhvbWE7Y2F0ZWdvcnlJZD1jaXR5LXRvd24tdmlsbGFnZTtzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg"
}
}
}
In response no object references
Is it a bug or not every place has this external id?
I am responding as member of the team around HERE Places API.
Yes, not every place has a pvid. That is why I would suggest using the Sharing Id instead. I realize that the documentation should be improved to clarify that.
The Sharing Ids can be obtained by adding show_refs=sharing to either your search query or a place details request. It can be found in the field references. Once you have the sharing id you can you the lookup endpoint as you intended.
Take a look at:
https://places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD00YWU2ZWZjNi01ZjgzLTUwYTQtOTI4OS0xZjliMGMwNWY3NjBfMTUwNzA0NDE0OTc3NV84MTI5XzU1NDcmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid
and
https://places.cit.api.here.com/places/v1/places/8409q8yy-6af3c3e50bcb4f859686797b2be5773d;context=Zmxvdy1pZD00YWU2ZWZjNi01ZjgzLTUwYTQtOTI4OS0xZjliMGMwNWY3NjBfMTUwNzA0NDE0OTc3NV84MTI5XzU1NDcmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid
On those two examples, the only difference is the placeId.
In the docs, there's not a single reference saying that the external identifier is required or existant for every place.
Since it represents an external identifier, I believe we could assume that it's not required.
And it's what we just saw with your place (8403fv6k-d1b2fde0616e0326e321a54b88cd9f53): this one don't have any external identifier.
Based on your comments, what you need is the information about a place.
So, after you run your first query, you should get something like:
{
title: "Southwest Test & Balance",
position: [],
id: "8403fv6k-d1b2fde0616e0326e321a54b88cd9f53",
href: "https://[...]"
}
With this ID, you could access it:
places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD0zYTFlZjg5ZS02ZTY5LTUxYmEtYWFkYS1kY2UwZWMyNDdkMDBfMTUwNzEzNjUxNjI5N182NjExXzc2OTgmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg
Or directly using the href information.
This response already is giving you the ID and URL to access all the info of a single place.
You don't need any other external ID or reference.
There seems to be an inconsistency with the responses for Yodlee's getSiteLoginForm REST API function.
For a site that has a login field with radio buttons, sometimes the data coming back from Yodlee for that particular field will look like this:
{
"fieldInfoList": [
{
"validValues": [
"1",
"2",
"3",
"4"
],
"displayValidValues": [
"1",
"2",
"3",
"4"
],
"valueIdentifier": "OPTIONS",
"valueMask": "LOGIN_FIELD",
"fieldType": {
"typeName": "OPTIONS"
},
"size": 20,
"maxlength": 40,
"name": "OPTIONS",
"displayName": "Issue Number",
"isEditable": true,
"isOptional": false,
"isEscaped": false,
"helpText": "76367",
"isOptionalMFA": false,
"isMFA": false
}
]
}
and other times it looks like this:
{
"validValues": [
"1",
"2",
"3",
"4"
],
"displayValidValues": [
"1",
"2",
"3",
"4"
],
"valueIdentifier": "OPTION",
"valueMask": "LOGIN_FIELD",
"fieldType": {
"typeName": "OPTIONS"
},
"size": 20,
"maxlength": 40,
"name": "OPTION",
"displayName": "Issue Number",
"isEditable": true,
"isOptional": false,
"isEscaped": false,
"helpText": "76367",
"isOptionalMFA": false,
"isMFA": false
}
It's the same field but the valueIdentifier value has changed and the data isn't being enclosed in a fieldInfoList variable.
What would be the reason for this response data-set changing between two attempts if there's no difference in the code?
In addition to that, could a similar response inconsistency be affecting other API functions from Yodlee, and if so how does one deal with this uncertain variance?
We did analysis and Yodlee provides every time same response, no matter how many attempts you'll do. While I am assuming that you might be confused between getSiteLoginForm and getLoginFomForContentService, as both are two different APIs and belongs to approach i.e., Site Based and Container Based respectively. And the response you have mentioned first comes when you use getSiteLoginForm while the later one comes with getLoginFormForContentService.
Hope this helps as there is no issue with the API, these are two different response from 2 different APIs.
I'm trying to update an option value using the BigCommerce api.
The documentation says PUT /options/values/id.json
The console says PUT options/id/values.json
I think it should be PUT options/id/values/id.json, which returns a 200 response code, but does not execute the update.
Any information on what the right endpoint is for this and if it works?
Basically, if you do a GET request on options
{
"id": 3,
"name": "Colors",
"display_name": "Color",
"type": "CS",
"values": {
"url": "https://store-xxx.mybigcommerce.com/api/v2/options/3/values.json",
"resource": "/options/3/values"
}
}
The resource endpoint shows that the URL is options/id/values.json. But, this gives you all the values associated with the option. If you want to retrieve a specific option the endpoint is something similar to /api/v2/options/3/values/7.json
{
"id": 7,
"option_id": 3,
"label": "Silver",
"sort_order": 1,
"value": "#cccccc"
}
Doing a PUT request on this - (On REST console, setting the header content-type to application/json and sending raw JSON data) updates the label - Changed Silver to silver)
{
"id": 7,
"option_id": 3,
"label": "silver",
"sort_order": 1,
"value": "#cccccc"
}