Pavan Atri
2014-07-31 21:05:15 UTC
Hello,
I am trying to create a HTML file attachment in my group library, using the
*attachment_simple* and *attachment_both* functions in the Pyzotero wrapper
for Zotero API. *It works fine on the user library*(my personal library)
but fails when I use it on a group library, giving a *UserNotAuthorised *response.
I have the Admin permission in the group library. Below is the code and the
error response:
The below code fetches HTML content from an XML file and creates a File
object out of it, which is the file attachment to be created
from pyzotero import zotero
import xml.etree.ElementTree as exml
import codecs
*def addHTMLAtchmnt(itemId):#Code to locate XML file from where HTML
content is to be fetched item = zot.item(itemId) extra
=str(item[0][u'extra']) filename = extra[extra.rfind(".")+1:] +
"-atom.xml" doc = exml.parse(fileloc + filename) root =
doc.getroot() #FetchHTML content from the XML htmltext =
root.find('{http://www.w3.org/2005/Atom}content').text if htmltext !=
None: htmlfile =
codecs.open('htmlattchmnt.html','w',encoding='utf-8')
htmlfile.write(htmltext) htmlfile.close()
zot.attachment_simple(['htmlattchmnt.html'], itemId) print
'Attachment created'zot = zotero.Zotero(<groupId>, 'group',
<apiKey>)fileloc = "D:\\GitHub\\awol-backup\\"#Add HTML attachment to the
Parent record with ID: *
*2GMSK2MJaddHTMLAtchmnt('2GMSK2MJ')*
*Error Response:*
Traceback (most recent call last):
File
"C:\Users\Pavan\workspace2\ZoteroTest\atri\zotero\test\zot_html_attachment.py",
line 51, in <module>
addHTMLAtchmnt('9U9NBFEF')
File
"C:\Users\Pavan\workspace2\ZoteroTest\atri\zotero\test\zot_html_attachment.py",
line 25, in addHTMLAtchmnt
zot.attachment_simple(['htmlattchmnt.html'], itemId)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 1031, in
attachment_simple
return self._attachment(to_add, parentid)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 782, in
_attachment
created = create_prelim(payload)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 692, in
create_prelim
error_handler(req)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 1238, in
error_handler
raise error_codes.get(req.status_code)(err_msg(req))
pyzotero.zotero_errors.UserNotAuthorised:
Code: 403
URL: https://api.zotero.org/users/<groupID>/items/9U9NBFEF/children?key=<
apiKey>
Method: POST
Response: Forbidden
In the Error response I see that the POST URL has* /users/* which I
actually think should be* /groups/* since am trying to create it in a group.
Please let me know if I've missed out on anything.
Thank you!
Regards,
Pavan
I am trying to create a HTML file attachment in my group library, using the
*attachment_simple* and *attachment_both* functions in the Pyzotero wrapper
for Zotero API. *It works fine on the user library*(my personal library)
but fails when I use it on a group library, giving a *UserNotAuthorised *response.
I have the Admin permission in the group library. Below is the code and the
error response:
The below code fetches HTML content from an XML file and creates a File
object out of it, which is the file attachment to be created
from pyzotero import zotero
import xml.etree.ElementTree as exml
import codecs
*def addHTMLAtchmnt(itemId):#Code to locate XML file from where HTML
content is to be fetched item = zot.item(itemId) extra
=str(item[0][u'extra']) filename = extra[extra.rfind(".")+1:] +
"-atom.xml" doc = exml.parse(fileloc + filename) root =
doc.getroot() #FetchHTML content from the XML htmltext =
root.find('{http://www.w3.org/2005/Atom}content').text if htmltext !=
None: htmlfile =
codecs.open('htmlattchmnt.html','w',encoding='utf-8')
htmlfile.write(htmltext) htmlfile.close()
zot.attachment_simple(['htmlattchmnt.html'], itemId) print
'Attachment created'zot = zotero.Zotero(<groupId>, 'group',
<apiKey>)fileloc = "D:\\GitHub\\awol-backup\\"#Add HTML attachment to the
Parent record with ID: *
*2GMSK2MJaddHTMLAtchmnt('2GMSK2MJ')*
*Error Response:*
Traceback (most recent call last):
File
"C:\Users\Pavan\workspace2\ZoteroTest\atri\zotero\test\zot_html_attachment.py",
line 51, in <module>
addHTMLAtchmnt('9U9NBFEF')
File
"C:\Users\Pavan\workspace2\ZoteroTest\atri\zotero\test\zot_html_attachment.py",
line 25, in addHTMLAtchmnt
zot.attachment_simple(['htmlattchmnt.html'], itemId)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 1031, in
attachment_simple
return self._attachment(to_add, parentid)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 782, in
_attachment
created = create_prelim(payload)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 692, in
create_prelim
error_handler(req)
File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 1238, in
error_handler
raise error_codes.get(req.status_code)(err_msg(req))
pyzotero.zotero_errors.UserNotAuthorised:
Code: 403
URL: https://api.zotero.org/users/<groupID>/items/9U9NBFEF/children?key=<
apiKey>
Method: POST
Response: Forbidden
In the Error response I see that the POST URL has* /users/* which I
actually think should be* /groups/* since am trying to create it in a group.
Please let me know if I've missed out on anything.
Thank you!
Regards,
Pavan
--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to zotero-dev-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to zotero-dev-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.