I am trying to pass two email addresses (JSON value) as follows:
Line#91 <cfhttpparam type="formfield" name="inpEmailObject"
value="["email1#gmail.com","email2#gmail.com"]" />
However, I am ending up with the following error:
Invalid token # found on line 91 at column 75.
The CFML compiler was processing:
The tag attribute email1, on line 91, column 69.
A cfhttpparam tag beginning on line 91, column 9.
How can I pass email address in the value field?
If you want to include the double-quote as part of the string you're sending, double it.
value="[""email1#gmail.com"",""email2#gmail.com""]"
Or, as Antony suggests, change one set to be single-quotes. This should work:
value='["email1#gmail.com","email2#gmail.com"]'
Related
I am new to HDF5 file format and I have a data(images) saved in HDF5 format. The images are saved undere a group called 'data' which is under the root group as Carrays. what I want to do is to retrive a slice of the saved images. for example the first 400 or somthing like that. The following is what I did.
h5f = h5py.File('images.h5f', 'r')
image_grp= h5f['/data/'] #the image group (data) is opened
print(image_grp[0:400])
but I am getting the following error
Traceback (most recent call last):
File "fgf.py", line 32, in <module>
print(image_grp[0:40])
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
(/feedstock_root/build_artefacts/h5py_1496410723014/work/h5py-2.7.0/h5py/_objects.c:2846)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
(/feedstock_root/build_artefacts/h5py_1496410723014/work/h5py
2.7.0/h5py/_objects.c:2804)
File "/..../python2.7/site-packages/h5py/_hl/group.py", line 169, in
__getitem__oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "/..../python2.7/site-packages/h5py/_hl/base.py", line 133, in _e name = name.encode('ascii')
AttributeError: 'slice' object has no attribute 'encode'
I am not sure why I am getting this error but I am not even sure if I can slice the images which are saved as individual datasets.
I know this is an old question, but it is the first hit when searching for 'slice' object has no attribute 'encode' and it has no solution.
The error happens because the "group" is a group which does not have the encoding attribute. You are looking for the dataset element.
You need to find/know the key for the item that contains the dataset.
One suggestion is to list all keys in the group, and then guess which one it is:
print(list(image_grp.keys()))
This will give you the keys in the group.
A common case is that the first element is the image, so you can do this:
image_grp= h5f['/data/']
image= image_grp(image_grp.keys[0])
print(image[0:400])
yesterday I had a similar error and wrote this little piece of code to take my desired slice of h5py file.
import h5py
def h5py_slice(h5py_file, begin_index, end_index):
slice_list = []
with h5py.File(h5py_file, 'r') as f:
for i in range(begin_index, end_index):
slice_list.append(f[str(i)][...])
return slice_list
and it can be used like
the_desired_slice_list = h5py_slice('images.h5f', 0, 400)
Trying to let users update column values on existing records for a specific table named "Scenario." The record being updated is identified by an index column called "Scenario_Key", unique to each instance of this class. The code I already have produces a dictionary of key, value pairs where key is the name of the column being updated and value is the value being inserted into it. To update the sqlite database I'm trying the following:
cursor.execute("""UPDATE Scenario SET ?=? WHERE Scenario_Key=?;""", (key, new_val, self.scenario_key))
But when I try to execute by clicking the "Save and Close" button, I get the following:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
return self.func(*args)
File "/Users/xxx/Documents/Consulting/DCA/Damage Control Assistant/EditScenarioWindow.py", line 91, in <lambda>
SaveAndCloseButton = Button(ButtonFrame, text="Save and Close", command=lambda: self.SaveAndCloseWindow())
File "/Users/xxx/Documents/Consulting/DCA/Damage Control Assistant/EditScenarioWindow.py", line 119, in SaveAndCloseWindow
cursor.execute(cmd_string, (key, new_val, self.scenario_key))
OperationalError: near "?": syntax error
I've read over sqlite3.OperationalError: near "?": syntax error, but I'm trying to do a single sqlite query where all the variables have already been calculated, not get values from the database and build a query from there. I'm supplying the positional arguments as a tuple. So why doesn't sqlite3 like the query I'm submitting?
You cannot parametrize column names. While being cognisant of the possibility of SQL Injection attacks, you could instead do:
cursor.execute("""UPDATE Scenario
SET {}=?
WHERE Scenario_Key=?;""".format(key),
(new_val, self.scenario_key))
I met a problem recently playing around with Scrapy .
consider the situation:
A json array that placed in a textarea wrapper
<div id="example">
<textarea>
[{"type":"\u8d4f\u82b1","sub":[{"sname":"\u5a7a\u6e90","sid":"440a8cc57454b0656bc5b1f1","surl":"wuyuan"},{"sname":"\u7f57\u5e73","sid":"ded1be78733fb2cc70c021f4","surl":"luoping"},{"sname":"\u6d1b\u9633","sid":"f77d6111526fb820db6efaf3","surl":"luoyang"},{"sname":"\u5174\u5316","sid":"700cac1d394cbc1a34e154c3","surl":"xinghua"},{"sname":"\u4eac\u90fd","sid":"bf34d1b18b0036d9222ef5d9","surl":"jingdu"}]},{"type":"\u8d2d\u7269","sub":[{"sname":"\u8fea\u62dc","sid":"b710d6f3c821e59aba1c29d5","surl":"dibai"},{"sname":"\u6cf0\u56fd","sid":"e524735691f256c0a53e8ffb","surl":"taiguo"},{"sname":"\u97e9\u56fd","sid":"d7e376b3690f23d1dc24bbfb","surl":"hanguo"},{"sname":"\u9999\u6e2f","sid":"d7e376b3690f23d1dc24bbfb","surl":"xianggang"},{"sname":"\u65b0\u52a0\u5761","sid":"b15d7068c2f160adbc2c83fb","surl":"xinjiapo"}]},{"type":"\u8e0f\u9752","sub":[{"sname":"\u9ec4\u5c71","sid":"6701f1153f0fd41f975775f3","surl":"huangshan"},{"sname":"\u91ce\u4e09\u5761","sid":"da679613cd1729d6be7822fd","surl":"yesanpo"},{"sname":"\u4e39\u971e\u5c71","sid":"b6ca381b2120f8ccda001fdd","surl":"danxiashan"},{"sname":"\u5341\u6e21","sid":"36eb66d6c4365b0af2c94bfe","surl":"shidu"},{"sname":"\u5e90\u5c71","sid":"9a06d41f975780992b0773fa","surl":"lushan"}]},{"type":"\u6444\u5f71","sub":[{"sname":"\u5357\u4eac","sid":"1e7451eeeb69e222608ca2f4","surl":"nanjing"},{"sname":"\u745e\u58eb","sid":"ad2cb39f09736a7351eea7fb","surl":"ruishi"},{"sname":"\u676d\u5dde","sid":"440a8cc57454b0656bc5b1f1","surl":"hangzhou"},{"sname":"\u4e91\u5357","sid":"17070a5c91ca872746461bf4","surl":"yunnan"},{"sname":"\u5e03\u62c9\u683c","sid":"1e7b51eeeb69e222608ca2fb","surl":"bulage"}]}]
</textarea>
</div>
using xpath('//*[#id="example"]/textarea/text()') i can fetch the json array, but there is a problem ,see the pic below:
the xpath is different because one is for example and the other one is from my dev.so its not a big deal
as you can see , at the beginning and ending, there are extra [u'\r\n and \r\n ]
i want to convert it to json so that i can iterate the json array,i use json.loads(),but an error occurs and says
>>> json.loads(response.xpath('//*[#id="J-head-menu"]/li[1]/textarea/text()').extract())
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
If i remove the extra stuff manually,it will be working,so,here is what i think,i should remove the extra stuff around the json,but i tried many way but failed,the type response.xpath() returns is not string but a list,so how to address it? i have no ideas,anyone does? thanks in advance!
In xpath normalize-space should help removing unwanted leading and trailing whitespace. xpath('normalize-space(//*[#id="example"]/textarea/text())') should work.
However, this will also replace sequences of whitespace characters with a single whitespace character. See also: https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/normalize-space.
response.xpath('//*[#id="example"]/textarea/text()').extract()[0].strip()
solves this problem !!
Using Py2Neo 2.0 and Pycharm Community Edition 4
I'm trying to update a node. First I get the node object, change a node property, bind to the database, and then push the node. I get a slew of errors. Here is the code.
user_node = Graph().find_one('USER',
property_key='email',
property_value='marnee#marnee.com')
user_properties['mission_statement'] = 'New mission statement'
user_node.bind(uri=Graph().uri)
user_node.push()
The node is found, it does have a mission_statement property. The exception seems to happen on .push(). The Graph() uri is good, too.
Below are the errors.
I had been able to do this successfully about a week ago. I have not updated any packages recently.
The really weird part is that if I have a breakpoint and run this in debug mode I do not get any errors and the node is updated successfully.
Traceback (most recent call last):
File "C:/Users/Marnee Dearman/PycharmProjects/AgoraDev/py2neo_2.0_tests/create_rel_int_loc.py", line 27, in <module>
user_node.push()
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\core.py", line 1519, in push
batch.push()
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\push.py", line 73, in push
self.graph.batch.run(self)
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 99, in run
response = self.post(batch)
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 88, in post
data.append(dict(job, id=i))
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 232, in __iter__
yield "to", self.target.uri_string
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 180, in uri_string
uri_string = self.entity.ref
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\core.py", line 1421, in ref
return "node/%s" % self._id
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\core.py", line 1412, in _id
self.__id = int(self.uri.path.segments[-1])
ValueError: invalid literal for int() with base 10: ''
Using Nigel's advice below, I got this to work. It was a usage error on my part:
user_node = Graph().find_one('USER',
property_key='email',
property_value='marnee#email.com')
user_node.properties['mission_statement'] = 'New mission statement'
user_node.push()
There are a couple of problems with your code so I will try to clarify the correct usage of these methods.
The bind method is used to connect a local entity (in this case, Node) to a corresponding remote equivalent. You should generally never need to use this method explicitly as entities are typically bound automatically on creation or retrieval. In your case, the find_one method does exactly this and constructs a client-side node that is bound to a corresponding server-side node; an explicit bind is not required.
The second issue is with your usage of bind. The URI taken by this method is that of a specific remote resource. You have passed the URI of the Graph itself (probably http://localhost:7474/db/data/) instead of that of the Node (such as http://localhost:7474/db/data/node/2345). The actual error that you see is caused by py2neo attempting to strip the ID from the URI and failing.
The simple solution is to remove the bind call.
i am attaching a file from a particular path c:\important\log.txt
sender = 'poojagupta4112#gmail.com'
receiver = ['shubh4112#gmail.com']
message = """From: From Pooja Gupta <poojagupta4112#gmail.com>
To: To Shubha Goel <shubh4112#gmail.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
file_name = 'C:\important\log.txt'
msg=MIMEMultipart()
msg['From'] = sender
msg['To'] = receiver
msg['Subject'] = message
msg['Date'] = email.Utils.formatdate(localtime=True)
# build the attachment
att = MIMEBase('application', 'base64')
att.set_payload(open(file_name, 'rb').read())
email.Encoders.encode_base64(att)
att.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file_name))
msg.attach(att)
print 'successfully built attachment'
try:
session = smtplib.SMTP('smtp.gmail.com',587)
print 'Starting..'
session.ehlo()
print 'ehlo executed..'
session.starttls()
print 'starttls done'
session.login(sender,'snxzoumwhpybzvmo')
print 'logged in'
session.sendmail(sender,receiver,msg.as_string())
print 'sendmail executed..now quitting'
session.close()
except smtplib.SMTPRecipientsRefused:
print 'Recipient refused'
except smtplib.SMTPAuthenticationError:
print 'Auth error'
except smtplib.SMTPSenderRefused:
print 'Sender refused'
except smtplib.SMTPException:
print('Error')
It keeps on giving me the same error of Attribute error list object has no attribute lstrip
the following is the error, stack trace :
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
execfile('C:\important\secret_file.pyw')
File "C:\important\secret_file.pyw", line 45, in <module>
session.sendmail(sender,receiver,msg.as_string())
File "C:\Python27\lib\email\message.py", line 137, in as_string
g.flatten(self, unixfrom=unixfrom)
File "C:\Python27\lib\email\generator.py", line 83, in flatten
self._write(msg)
File "C:\Python27\lib\email\generator.py", line 115, in _write
self._write_headers(msg)
File "C:\Python27\lib\email\generator.py", line 164, in _write_headers
v, maxlinelen=self._maxheaderlen, header_name=h).encode()
File "C:\Python27\lib\email\header.py", line 410, in encode
value = self._encode_chunks(newchunks, maxlinelen)
File "C:\Python27\lib\email\header.py", line 370, in _encode_chunks
_max_append(chunks, s, maxlinelen, extra)
File "C:\Python27\lib\email\quoprimime.py", line 97, in _max_append
L.append(s.lstrip())
AttributeError: 'list' object has no attribute 'lstrip'
Please Help.
it was a small error. receiver parameter was list type. either it should be list converted to string using join method or if it is a single recipient, then pass it as a string only
receiver = ['shubh4112#gmail.com']
This is a list but msg['To'] is expecting a string and hence the error.
You can use ','.join(receiver) and that should solve your problem.
This appears to be a issue from smtplib. The documentation clearly says that it accepts a list
The arguments are:
- from_addr : The address sending this mail.
- **to_addrs : A list of addresses to send this mail to. A bare
string will be treated as a list with 1 address.**
- msg : The message to send.
Usage from documentation:
"Example:
>>> import smtplib
>>> s=smtplib.SMTP("localhost")
**>>> tolist=
["one#one.org","two#two.org","three#three.org","four#four.org"]**
>>> msg = '''\\
... From: Me#my.org
... Subject: testin'...
...
... This is a test '''
>>> s.sendmail("me#my.org",tolist,msg)"
Also as said in the documentation if recipients are passed as string, mail is being sent to first mailid only.
So actually the problem is that SMTP.sendmail and email.MIMEText need two different things.
email.MIMEText sets up the "To:" header for the body of the e-mail. It is
ONLY used for displaying a result to the human being at the other end, and
like all e-mail headers, must be a single string. (Note that it does not
actually have to have anything to do with the people who actually receive
the message.)
SMTP.sendmail, on the other hand, sets up the "envelope" of the message for
the SMTP protocol. It needs a Python list of strings, each of which has a
single address.
So, what you need to do is COMBINE the two replies you received. Set
msg['To'] to a single string, but pass the raw list to sendmail:
emails = ['a.com','b.com', 'c.com']**
**msg['To'] = ', '.join( emails )
....
s.sendmail( msg['From'], emails, msg.as_string() )****
I have the same problem, my solution:
msg['To'] = receiver
receive must be string like 'aa#bb.com,bb#cc.com', not list