Why does python gives an error when running this function? - python

I am trying to run the get_item_offers_batch() function from the python amazon sp api: https://python-amazon-sp-api.readthedocs.io/en/latest/endpoints/products/#sp_api.api.Products.get_item_offers_batch
However I am getting the following error when the function runs in python: sp_api.base.exceptions.SellingApiBadRequestException: [{'code': 'InvalidInput', 'message': 'InvalidInput', 'details': ''}]
Here is my code
request = [dict(asin="B08CGT4FXL", MarketplaceId="A1PA6795UKMFR9", item_condition='new'), dict(asin="B07KF8LPBC", MarketplaceId="A1PA6795UKMFR9", item_condition='new')]
res = Products(credentials=client_config, marketplace=Marketplaces.DE).get_item_offers_batch(requests_=request)
print(res.payload)
It asks for a List of dictionaries, which I have provided
What could be the issue ?
Required parameters
Tried to rung the python sp api batch function and the script crashes with invalid input code.

Related

I have a problem with the session ID http request

when I use the session code with the request in python it works but in php it tells me that it is invalid but when I take the session code from python and put it in php it works!
Or in other words, the session ID that I fetch through a request works, but in php it does not work
The function I used in Python:
def getSession():
url='https://ex.com'
data={
'session_id':'',
'campaign_id':'57430',
'embedded':'true',
'attribution_data':'',
'fund':'',
'amount':'1',
'frequency':'once',
'team':'',
'member':'',
}
r=post(url,data=data).json()['session']['id']
return r
The function I used in PHP:
function getSession(){
$url="https://ex.com";
$request=curl_init($url);
$data=http_build_query([
'session_id'=>'',
'campaign_id'=>'57430',
'embedded'=>'true',
'attribution_data'=>'',
'fund'=>'',
'amount'=>'1',
'frequency'=>'once',
'team'=>'',
'member'=>'',
]);
curl_setopt_array($request,[
CURLOPT_POST=>1,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_HTTPHEADER=>['Accept:application/json','Content-Type: application/x-www-form-urlencoded'],
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_COOKIESESSION=>TRUE
]);
The two perform the same purpose and they fetch the session id successfully, but the problem is that the id I get from Python only works and the one I get from php tells me it is expired!

"Bad Request" when creating an SQLServerLinkedService

I am trying to create an SQL Server Linked Service for Azure Data Factory from within Python. All the dependencies are imported and the data factory gets created successfully. It is failing on creating the Linked Service.
Here is my pseudo-code running from Python:
ls_name = 'Blah'
properties = SqlServerLinkedService(
connection_string="blahblah.database.windows.net",
connect_via={"referenceName": "AutoResolveIntegrationRuntime", "type": "IntegrationRuntimeReference"},
user_name="my-user-name",
password=SecureString("my-plaintext-password")
)
ls = adf_client.linked_services.create_or_update( resource_group_name=rg_name, factory_name=df_name, linked_service_name=ls_name, linked_service=properties)
For one, if I keep the format of the SecureString the way it is above, I get error about 2 positional arguments where only 1 is required, if i take out the password line altogether, I get "Bad Request" when create_or_update function runs at the bottom. They Microsoft Python SDK documentation is terribly lacking. Can someone help me figure out how to code this correctly?
File "/usr/local/lib/python3.8/dist-packages/azure/mgmt/datafactory/operations/_linked_services_operations.py", line 190, in create_or_update
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Bad Request'
We experienced the same issue when creating Azure Data Factory linked services; when creating a linked service you need to create a LinkedServiceResource:
ls_name = 'Blah'
properties = LinkedServiceResource(properties=SqlServerLinkedService(
connection_string="blahblah.database.windows.net",
connect_via={"referenceName": "AutoResolveIntegrationRuntime", "type": "IntegrationRuntimeReference"},
user_name="my-user-name",
password=SecureString("my-plaintext-password")
))
ls = adf_client.linked_services.create_or_update( resource_group_name=rg_name, factory_name=df_name, linked_service_name=ls_name, linked_service=properties)

Iis there a empty function thats returned which i am not aware about while using the python code module?

I am currently writing a zapier "zap" that detects for a certain gitlab project when a pipeline status is changed it then sends a embed to discord depending on what status it is at this is all for my continous intergration error reporting, to do this I have used multiple webhooks, the first webhook detects when there is a pipeline change via gitlabs webhook system (this works fine), then another one which gets the recent tag so it can display what tag is being deployed (this also works fine), then a couple selection statements in the form of python code which determines what type of embed should be sent to discord (problem), and then finally a custom webhook request which sends the discord embed (also works fine).
The code which currently isn't working is in python:
if "name: unit_test" in input_data.get("Build") and "status: failed" in input_data.get("Build"):
output = [{'colour': 13832489, 'text': 'Unit test has Failed'}]
elif "name: unit_test" in input_data.get("Builds") and "status: passed" in input_data.get("Builds"):
output = [{'color': 7841089, 'text': 'Unit test has passed test'}]
elif "name: deploy_development" in input_data.get("Builds") and "status: pending" in input_data.get("Builds"):
output = [{'color': 6199517, 'text': 'Version' + input_data.get("version") + 'is being pushed to production...' }]
elif "name: deploy_development" in input_data.get("Builds") and "status: passed" in input_data.get("Builds"):
output = [{'color': 7841089, 'text': 'Deployed' + input_data.get("version") + 'to production!' }]
and the inputs are
(source: edbrook.site)
this are stored in a disctionary input_data per normal code with zapier.
The error I receive when I test only the python code module is this: TypeError: argument of type 'NoneType' is not iterable, upon looking into this error, it happens when a function is returned without a value. I havnt used a function, so what function is being returned?
and input would be appreciated, Thanks.
I would guess that input_data.get("Build") is returning None. dict.get returns None if the key isn't in the dictionary, which would give that same TypeError.

JIRA API - Python Lib - Create_Issue - Option id 'null' is not valid

So my issue is with the Python Library for the JIRA API. We are using JIRA as a asset management database (Yes I know its normal used by dev's and we use it for that as well but this was a case were it worked well) to keep track of are server configs (Memory, CPU, Location on the Rack ..etc..)
Using this function I am having it create a Issue under a Project and pull the information for the fields from another API.
(note that I cant give clues as to who I work for so the code is edited - however it all works expect when i add one line)
def create_compute_node_in_jira(self, compute_node_name ,user_name, password, info_dic):
help_obj = helper()
jira = JIRA("https://",basic_auth=(user_name,password))
#Uses a dic to create the fields / info for the Issue
issue_dict = {
'project': {'key': <project>},
'summary': compute_node_name,
'issuetype': {'name': 'Server Hardware'},
'customfield_10500': str(info_dic["Hostname"]),
'customfield_11007': {'value': str("2U")},
'customfield_11006': str(info_dic["Aggr0-IP"]),
'customfield_10510': {'value': str(7)},
'customfield_10501': str(info_dic["Serial-Number"])
'customfield_10502': {'value': str(<server>)},
'customfield_10503': str(help_obj.data_parser_sm(info_dic["Hostname"])),
'customfield_10509': {'value': str("<OS>")},
'customfield_10504': {'value': str("<mem>")},
'customfield_10505': str(help_obj.data_parser_cpu(info_dic["CpuType"])),
'customfield_10507': {'value': str(info_dic["Cpu-Core"])},
'customfield_10508': {'value': str(<OS Version>)},
'customfield_11008': {'value': str("CMH")}
}
jira.create_issue(fields=issue_dict)
return "[*]Created ticket" # Should exit script after this is returned
The line - 'customfield_11008': {'value': str("CMH")} - causes the function to return the following expection:
jira.utils.JIRAError: JiraError HTTP 400
text: Option id 'null' is not valid
url: https:///rest/api/2/issue
however when i omit that line it runs with out a problem. I tried CMH lower case - capital ..etc.. and it still breaks the scripts. I even went through the web gui and copied the "CMH" entry in another ticket and it stilled caused a problem. Has anybody seen this before / have any guesses as to why it is breaking ?
So after a while of playing around with JIRA I found out it was my own mistake. It seems this error is caused when you post to a field using the API a "value" that it does not understand. A example was I was using the wrong custom field and the JIRA Field that I was posting to was not setup to take the value I was using.
You will see this error when the field's value is expected to match an option list, and you are trying to send a value which is not on this list.

unknown RT error message

I'm trying to debug a script that's trying to talk to RT (Request Tracker) and I'm getting the following output:
RT/3.6.6 409 Syntax Error
# Syntax Error
>>ARRAY(0x2b3495f37750)
I have no idea what this error means in the context of RT given the astounding lack of detail making it difficult to debug. Here's the associated code for a little context, it's a script trying to create a ticket.
import requests
def combDicts(dicts):
out = {}
for d in dicts:
out.update(d)
return out
operPath = 'ticket/new'
credentials = {'user': 'myuser', 'pass': 'mypassword'}
content = {
'content': {
'id': 'ticket/new',
'Subject': 'Python Script Test',
'Queue': 'General - unassigned',
}
}
r = requests.post('https://rt.hdms.com/REST/1.0/' + operPath, params=combDicts((credentials, content)), verify = False)
print r.text
If I comment out all but the Queue line of the content dict the error changes to:
RT/3.6.6 409 Syntax Error
# Syntax Error
>> Queue
The crux of my question is this: Does anyone know what this error means or know where I can find documentation on what all the RT errors are and what could cause them?
You'll find much more information in the logs on the RT server itself, especially if you up the log level to debug. You might have better luck using one of the python libraries available for calling RT. However, the version of RT you're running is fairly old, released in Jan. 2008. You may have trouble using current libraries with an old version of RT.

Categories

Resources