I am trying to figure out how to send an email message through AWS SES using mime-mail-ses package. I used renderSendMailSES example from Yesod wiki to try the code below - I am using renderMail here to debug the error in mail body validation:
*Main> let textPart = Part {partType = "text/plain; charset=utf-8",
partEncoding = None, partFilename = Nothing, partHeaders = [], partContent = "Testing"}
*Main> let htmlPart = Part { partType = "text/html; charset=utf-8",
partEncoding = None, partFilename = Nothing, partHeaders = [], partContent = "Testing"}
*Main> renderMail' (emptyMail $ Address Nothing "noreply#example.com") {
mailTo = [Address Nothing "test#example.com"] , mailHeaders = [ ("Subject",
"Testing email address")], mailParts = [[textPart, htmlPart]]}
I get this error:
*** Exception: renderParts called with null parts
This is quite head-scratcher because the above example doesn't seem any different from Yesod Wiki. I can't add attachment either because of the above error. An attachment if I am not mistaken, will look like this for mailParts:
mailParts = [[textPart,htmlPart],[attachment1]]
I looked in the code that is causing the error but can't figure out what is wrong.
I will very much appreciate pointers to resolve this error.
This is a versioning issue. I had a local patched copy of http-client from github (to add some streaming validation that wasn't in stackage yet) which seems to be the culprit here. I fixed it by changing the http-client to point to http-client on stackage with the release version that had my fixes (0.4.31). Now, it works fine.
Related
i have an Api function in Golang that receive a json data and good working with postman
but i want te call api with python3 but error in parse body
this is my golang code:
var approve bson.M
err := c.BodyParser(&approve)
and this is my data in patch api :
{
"result" : true
}
and this is my python script:
jsondata = bson.BSON.encode({'result': True})
options = CodecOptions(document_class=collections.OrderedDict)
#decoded_doc = bson.BSON(jsondata).decode(codec_options=options)
decoded_doc = bson.decode(jsondata, codec_options=options)
r = requests.patch(approvurl,data=decoded_doc,headers={'Content-Type':'application/json','Authorization':API_KEY,'Imei':'1234567890','phone':'123456789','email':'test#gmail.com'} )
and my backend in my golang throw this exeption :
expected { character for map value
and i compare json object in wirshark :
this is for postman:
enter image description here
and
this is for my python script
enter image description here
please help me to solve my problem in python script
I think what's happening is that you're passing a Python dict using requests.patch's data parameter, which expects a string. It looks like you want to send JSON, so you should use the json parameter (which adds the application/json Content-Type automatically).
Also, it looks like you're encoding a Python dict to BSON format, only to re-decode it back to a Python dict again. Unless I'm missing something, you shouldn't need to do that.
So your Python script can be changed to a single call to requests.patch:
r = requests.patch(
approvurl,
json={'result': True},
headers={'Authorization': API_KEY, ...},
)
my problem solved by added a new function that check agent :
userAgent := string(c.Context().UserAgent())
//print("userAgent=", userAgent)
if strings.HasPrefix(userAgent, "python-requests") {
eq := c.Body() //("result")
if string(eq) == "result=True" {
print("jsonBody is", string(eq))
id, _ := primitive.ObjectIDFromHex(c.Params("id"))
print("Approving started=", true)
tnx`
I have a strange problem. I made a small application in node.js, using nodemailer to send emails each day.
And it's working perfectly when I run it from the terminal (for testing).
But when I add a job to crontab, then emails are sent but there is missing some of the content inside.
This is my transporter conf:
// send mail with defined transport object
let info = await transporter.sendMail({
priority: 'high',
from: '"Example" <example#gmail.com>', // sender address
to: 'recip#gmail.com', // list of receivers
subject: 'Example title: '+currentDate, // Subject line
text: '', // plain text body
html: header + missing + carrierStatArr + ending,// html body
attachments: attachments
});
And code for variables to html field:
let carrierStatArr = [], attachments = [];
let header = `<h1>some text ${currentDate}</h1><div><i>some text</br>some text</i></div>`;
let missing = `<h3 style="color:red;">some text: <b>${missingArr}</b></h3>`;
for (let i in checkResultArr) {
let imgName = checkResultArr[i].file;
let correctedImgName = imgName.substring(0,16);
carrierStatArr.push(`<p>Some text <b>${checkResultArr[i].name}</b>,</br>
<span>Some text: <b>${checkResultArr[i].status}</b></span></br>
<span><img src="cid:${correctedImgName}" width="1000px"/></span>
</p>`);
}
//console.log(carrierStatArr);
attachments = checkResultArr.map((file)=>{
let pat = '/var/www/html/public_html/MM1_service/images/';
let fi = file.file;
let fit = fi.substring(0,16);
return {path: pat+file.file, cid: fit};
});
//console.log(attachments[0].path);
let ending = `<hr size="1" width="100%" color="gray"><p><i>some text</i></p>`;
Of course, there are all data in arrays. And as I wrote, when I run this code manually using terminal /node sendmail.js/ it works perfectly, email contains all the information's, text, and images.
But when the script is run automatically by the cron job, the email has only header, missing, and ending variables (and the content from arrays is there) but the rest: carrierStatArr, attachments are missing.
Why is that? Manually work, run by cron not exacly.
Note: I managed to solve my problem by using the 'node-cron' module instead of the system cron. The app is working correctly.
But still I'm curious, from an academic point, why that problem occurred.
Has anyone had experience of trying to set metric filters on cloudwatch logs? Wondering if I have found a bug in Terraform?
So this is what I am trying to do;
resource "aws_cloudwatch_log_metric_filter" "AWS_Console_Login" {
name = "${var.aws_account_id}_Console_Login_Failure"
pattern = "{ ($.eventName = ConsoleLogin) && ($.errorMessage = "Failed authentication") }"
log_group_name = "${var.aws_cloudtrail_name}"
metric_transformation {
name = "${var.aws_account_id}_Console_Login_Failure"
namespace = "AccountMonitoring${var.aws_account_id}"
value = "1"
}
}
When I run a Terraform apply or validate I am getting this response;
Error: Error parsing cloudwatch.tf At 157:19: nested object expected: LBRACE got: ASSIGN
To be clear 157:19 relates to the line of code containing log_group_name with 19 being before the = symbol.
However I think this is to do with my pattern, if I remove log group.. and run a validate I get;
aws_cloudwatch_log_metric_filter.AWS_Console_Login: : invalid or unknown key: Failed
Am I asking too much with the AWS filter pattern I have?
Thanks
Stephen
Try escaping your quotes. This is a failure with syntax. The issue isn't the log_group_name line. It's the one above it.
resource "aws_cloudwatch_log_metric_filter" "AWS_Console_Login" {
name = "${var.aws_account_id}_Console_Login_Failure"
pattern = "{ ($.eventName = ConsoleLogin) && ($.errorMessage = \"Failed authentication\") }"
log_group_name = "${var.aws_cloudtrail_name}"
metric_transformation {
name = "${var.aws_account_id}_Console_Login_Failure"
namespace = "AccountMonitoring${var.aws_account_id}"
value = "1"
}
}
This appears to be fine. You should look at tflint. It's a part of the Terraform plugin for Visual Studio Code which helped me track down where the error was.
I have a do block in my Yesod tests and I want to be test the response with an expected response.
I attempted to create an expected response in this do block
let expectedUser = User [authorized = true, ident = "AdminUser", displayName = Nothing, id = 1, avatar = Nothing]
On this line I get the error
parse error on input ‘=’
Perhaps you need a 'let' in a 'do' block?
on the = after authorized. How would I rewrite this line so that it would work inside a do block?
The advice you're getting in the compile error is mostly irrelevant, because the parser really has no idea what you're trying to do here. Record syntax uses curly braces { and }, not [ and ]. So it should look like:
let expectedUser = User {authorized = true, ident = "AdminUser", displayName = Nothing, id = 1, avatar = Nothing}
and I would suggest some line breaks :)
let expectedUser = User { authorized = true
, ident = "AdminUser"
, displayName = Nothing
, id = 1
, avatar = Nothing
}
I am using the Servicestack.ormlite package. Everything has been working perfectly, but last night, all of a sudden, my InsertOnly command stopped working. This is the format of the InsertOnly command I am using, straight from the docs: https://github.com/ServiceStack/ServiceStack.OrmLite
Here is the command:
DB.InsertOnly(new ppNomination
{
PortalID = clientID,
NOM_sOtherExperience = nom.Title,
NOM_sExperienceDescription = nom.Description,
NOM_nWitness = nom.Witness,
NOM_dLastUpdated = DateTime.Now,
NOM_WrittenBy = nom.WrittenBy,
NOM_nSteward = nom.Nominee,
NOM_dDeliveredOn = nom.DeliveredOn,
NOM_dCreatedOn = nom.CreatedOn,
NOM_nApprovedBy = nom.ApproverId == -1 ? (int?)null : nom.ApproverId,
NOM_lActive = nom.Active,
NOM_lResubmitted = nom.IsResubmitted,
NOM_lReturned = nom.IsReturned,
NOM_lManagerApproved = nom.IsManagerApproved
},
a => a.Insert(p => new { p.PortalID, p.NOM_sOtherExperience, p.NOM_sExperienceDescription,
p.NOM_nWitness, p.NOM_dLastUpdated, p.NOM_WrittenBy, p.NOM_nSteward, p.NOM_dDeliveredOn,
p.NOM_dCreatedOn, p.NOM_nApprovedBy, p.NOM_lActive, p.NOM_lResubmitted, p.NOM_lReturned,
p.NOM_lManagerApproved }));
nom is the object being passed to the function, and I am just filling it up. This is the error I see:
variable 'p' of type 'Obsidian.Domain.DomainModel.ppNomination' referenced from scope '', but it is not defined
Any ideas as to what I might be doing wrong?