I am following the example code snippets the one in the right panel here. So I have a Recurly token and am trying to start a subscription using it.
subscription = Subscription()
subscription.plan_code = 'monthly'
subscription.currency = 'USD'
account = Account(account_code='1a')
account.email = 'mark#example.com'
account.first_name = 'mark'
account.last_name = 'lname'
billing_info = BillingInfo()
billing_info.number = '4111-1111-1111-1111'
billing_info.month = 1
billing_info.year = 2019
account.billing_info = billing_info
subscription.account = account
subscription.save()
I get error 500 when the code above runs. If I comment out subscription.save() the logs show ParseError: mismatched tag: line 6, col 2 which seems like xml parsing error. I get no error(but of course I presume the subscription is not being saved). Could this error be as a result of testing many times? or what could be the issue? am using sandbox.
My bad. I was missing recurly.SUBDOMAIN together with recurly.RECURLY_API_KEY settings. All save() methods for recurly.Subscription(), recurly.BillingInfo(), recurly.Account() were throwing the error when called.
Related
I'm trying to get some option chains using the pyetrade package. I'm working in Sandbox mode for a newly made Etrade account.
When I execute the following code, it executes fine, but the returned information is incorrect: I keep getting options for Apple between 2012 and 2015, instead of current Exxon-Mobil options (what I'm inputting). This is also true for if I ask for Google or Facebook or Netflix, I just keep getting outdated Apple options.
I'm not sure where I messed up, or if this is just something that's part of sandbox mode, so that's why I asked for help. Thank you!
(Note: Some of the code is sourced from: https://github.com/1rocketdude/pyetrade_option_chains/blob/master/etrade_option_chains.py)
The following is the function to get the option chain from the API:
def getOption(thisSymbol):
#Renew session / or start session
try:
authManager.renew_access_token()
except:
authenticate() #this works fine
#make a market object to pull what you need from
market = pyetrade.ETradeMarket(
consumer_key,
consumer_secret,
tokens['oauth_token'],
tokens['oauth_token_secret'],
dev=True
)
try:
#the dates returned are also
q = market.get_option_expire_date(thisSymbol,resp_format='xml')
#just formats the dates to be more comprehensible:
expiration_dates = option_expire_dates_from_xml(q)
except Exception:
raise
rtn = []
for this_expiry_date in expiration_dates:
q = market.get_option_chains(thisSymbol, this_expiry_date)
chains = q['OptionChainResponse']['OptionPair']
rtn.append(chains)
print()
return rtn
ret = getOption("XOM")
print(ret[0])
The API provider is explicit on this:
Note:
E*TRADE's sandbox doesn't actually produce correct option chains so this will return an error.
The sandbox is still useful for debugging e.g. the OAuth stuff.
No one could hardly make the sandbox-ed code work otherwise.
I'm working on a script to programmatically create a bunch of intents. I want to set the input context for these intents to a specific value. I have working code that creates the full intent - but I can't get the parameter for input context to work.
This works (in python), but does not create an input context:
intents_client = dialogflow_v2beta1.IntentsClient.from_service_account_json(PROJECT_JSON)
parent = intents_client.project_agent_path(PROJECT_ID)
training_phrases = []
part1 = dialogflow_v2beta1.types.Intent.TrainingPhrase.Part(text="hello ")
parts = []
parts.append(part1)
training_phrase = dialogflow_v2beta1.types.Intent.TrainingPhrase(parts=parts)
training_phrases.append(training_phrase)
text = dialogflow_v2beta1.types.Intent.Message.Text(text=["say hello"])
message = dialogflow_v2beta1.types.Intent.Message(text=text)
messages = []
messages.append(message)
intent = dialogflow_v2beta1.types.Intent(
display_name='Mike_Hello',
training_phrases=training_phrases,
messages=messages)
response = intents_client.create_intent(parent, intent, language_code=LANGUAGE)
But, when I add the following to my Intent definition:
intent = dialogflow_v2beta1.types.Intent(
display_name='Mike_Hello',
input_context_names=['5000'],
training_phrases=training_phrases,
messages=messages)
(ie - adding the input_context_names parameter)
The intent creation fails with an error:
Resource name does not match format 'projects/{project_id}/agent/sessions/{session_id}/contexts/{context_id}'
I tried creating a context with a context client and create_context, but it fails with the same error. The create_context API seems to me to be more related to creating a context for inputting into detect_intent, as it wants a live SESSION_ID as input.
I can replace ["5000"] in the input_context above with 'projects/PROJECT_ID/agent/sessions/-/contexts/5000', and I get the same error.
Bug? Or am I missing something?
Found the problem.
The entity string:
'projects/' + PROJECT_ID + '/agent/sessions/-/contexts/my_ctx_name'
works great.
The entity string:
'/projects/' + PROJECT_ID + '/agent/sessions/-/contexts/my_ctx_name'
does not work. My problem was the leading '/' before 'projects'.
I am using Django as the framework. I am using boto3 to create an AWS account in my views function. Every created aws account will have an AccountId. Before going into further details, here is my snippet :
org = boto3.client('organizations')
acc = org.create_account(
Email=email,
AccountName=lab_name,
IamUserAccessToBilling='ALLOW'
)
cid = acc['CreateAccountStatus']['Id']
time.sleep(70)
#GET ACCOUNT DETAILS
status = org.describe_create_account_status(
CreateAccountRequestId=cid
)
accid = status['CreateAccountStatus']['AccountId']
Initially I am creating the account. Like I mentioned before it takes some time (around 1 to 1.5 mins) to create the account. Then I need to GET the account details, one of the details being the AccountId. I tried increasing the sleep time to resolve this issue but that didn't help. I am getting an error when I try to GET the AccountId value in 'accid' declaration line. The error I am getting is:
KeyError: AccountId doesn't exist
This is probably happening because the account is not getting created yet and before that event my code is trying to fetch the AccountId value. How can I get the AccountId value then ? Should I try putting it in a loop or using try and except block to avoid the error message ? Please help. Thanks in advance.
status = org.describe_create_account_status(CreateAccountRequestId=cid)
while status.get('CreateAccountStatus',{}).get('AccountId',None) is None:
# sleep here
status = org.describe_create_account_status(CreateAccountRequestId=cid)
accid = status['CreateAccountStatus']['AccountId']
This will use the .get(key, default) of dict to supply it (or an empty dict) for 'CreateAccountStatus' and a None for 'AccountId' and loop while it is None.
About dict.get() and the dict.get-API
As pointed out by JonClements it might be more pythonic to use a while True: ... break ... construct for this:
while True:
status = org.describe_create_account_status(CreateAccountRequestId=cid)
try:
accid = status['CreateAccountStatus']['AccountId']
break
except KeyError:
time.sleep(30)
This avoids duplication of the status = ... line and makes for a more clearer flow.
Using try: ... except: fits better with the pythonic ask-forgiveness-not-permission approach.
In your acc['CreateAccountStatus'] variable, you should have a key State that will tell you when the creation is completed.
Here is the documentation, see in the Response Syntax
While creating a customer with Magento API using Python, i am getting this error:
Fault 1: "SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s), query was: SELECT `customer_entity`.* FROM `customer_entity` WHERE (entity_id ='firstname', '3876')"
But if i specify only the customer id, it will ask for all the other fields, and when i extend the dict with these values, the same error comes again.
Here is the dict i use to create the customer:
address = {}
address['customer_id'] = '3876'
address['addressdata']={}
address['addressdata']['firstname'] = 'firstname'
address['addressdata']['lastname'] = 'lastname'
address['addressdata']['city'] = 'city'
address['addressdata']['region'] = 'Texas'
address['addressdata']['region_id'] = 1
address['addressdata']['postcode'] = '23423' #ZIP
address['addressdata']['telephone'] = '3245235235' #phone
address['addressdata']['is_default_billing'] = False
address['addressdata']['is_default_shipping'] = False
address = proxy.call(session, 'customer_address.create', [address])
What do you think can be wrong here? Thanks
On the server side, enable sql logging (ideally only your API call should run against that server, in order to debug):
In Varien_Db_Adapter_Pdo_Mysql
lib/varien/Db/Adapter/Pdo/Mysql.php
set
protected $_debug = true;
protected $_logAllQueries = true;
and (if nor already there) create the folder defined in
protected $_debugFile = 'var/debug/sql.txt';
Run the API call then have a look at the log file and see what queries ran and why it gives an error.
You can also try these following links for same issue, might be helpfull for you.
https://stackoverflow.com/a/14864123
https://stackoverflow.com/a/34997348
https://stackoverflow.com/a/38326377
I am trying to get all comments of issues created in JIRA of a certain search query. My query is fairly simple:
import jira
from jira.client import JIRA
def fetch_tickets_open_yesterday(jira_object):
# JIRA query to fetch the issues
open_issues = jira_object.search_issues('project = Support AND issuetype = Incident AND \
(status = "Open" OR status = "Resolved" OR status = "Waiting For Customer")', maxResults = 100,expand='changelog')
# returns all open issues
return open_issues
However, if I try to access the comments of tickets created using the following notation, I get a key error.
for issue in issues:
print issue.raw['fields']['comment']
If I try to get comments of a single issue like below, I can access the comments:
single_issue = jira_object.issue('SUP-136834')
single_issue.raw['fields']['comment']
How do I access these comments through search_issues() function?
The comment field is not returned by the search_issues method you have to manually state the fields that must be included by setting the corresponding parameter.
just include the 'fields' and 'json_result' parameter in the search_issue method and set it like this
open_issues = jira_object.search_issues('project = Support AND issuetype = Incident AND \
(status = "Open" OR status = "Resolved" OR status = "Waiting For Customer")', maxResults = 100,expand='changelog',fields = 'comment',json_result ='True')
Now you can access the comments without getting keytype error
comm=([issue.raw['fields']['comment']['comments'] for issue in open_issues])
I struggled with the same issue. Assuming "issue" is an object of type Issue, and "jira" is an object of type JIRA, according to http://jira.readthedocs.org/en/latest/#issues
issue.fields.comment.comments
should work, but the fields object does not have any key "comment".
The other option mentioned there works for me:
jira.comments(issue)
So, for it to work you use the issues from your search result and call jira.comments. E.g.
issues = jira.search_issues(query)
comments = jira.comments(issues[index])
(My version of the library is 1.0.3, python 2.7.10)
from jira import JIRA
Jira = JIRA('https://jira.atlassian.com')
issue_num = "ISSUE-123"
issue = Jira.issue(issue_num)
comments = issue.fields.comment.comments
for comment in comments:
print("Comment text : ",comment.body)
print("Comment author : ",comment.author.displayName)
print("Comment time : ",comment.created)