Why ipdb session don't show every attribute of a brain with autocomplete?
For example brain.UID exists but it is not listed on ipdb autocomplete.
Is it any black magic on brain code?
With ipdb you can autocomplete all attributes of a brain:
>>> dir(brain)
['__add__', '__allow_access_to_unprotected_subobjects__', '__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__getstate__', '__hash__', '__implemented__', '__init__', '__len__', '__module__', '__mul__', '__new__', '__of__', '__providedBy__', '__provides__', '__record_schema__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_unrestrictedGetObject', 'getObject', 'getPath', 'getRID', 'getURL', 'has_key']
The metadata of a brain is not directly stored on the "brain". They are stored in a Btree (dataattribute) on the Catalog. You can access all informations stored in the data storage through the brain.
So if you try to access an attribute that doesn't exist on the brain it will try to return the value from the metadata storage if the key is available, otherwise AttributeErroris raised.
The magic happens somewhere here (ZCatalog).
Also check line 77:
# The catalog maintains a BTree of object meta_data for
convenient display on result pages. meta_data attributes
are turned into brain objects and returned by
searchResults.
In the ZMI on the portal_catalog tool, there' a metadata tab, which shows all accessible metadata infos.
Update:
Playing around with the catalog:
>>> plone = app.Plone
>>> catalog = plone.portal_catalog
>>> _catalog = catalog._catalog
>>> brain = catalog()[0]
# Metadata are stored in the data BTree, key is the RID of the brain.
>>> rid = brain.getRID()
>>> rid
704953343
>>> _catalog.data
<BTrees.IOBTree.IOBTree object at 0x10b158150>
>>> _catalog.data[rid]
# The UID is part of this tuple.
('2015-07-22T09:27:09+02:00', 'admin', '2015-07-22T15:12:07+02:00', '', 'None', 'None', '2015-07-22T15:12:07+02:00', (), 'xxx', u'xxx', '38e87a4b80704681b60781b66d37346c', DateTime('2015/07/22 09:27:9.236886 GMT+2'), DateTime('1969/12/31 00:00:00 GMT+2'), Missing.Value, Missing.Value, DateTime('2499/12/31 00:00:00 GMT+2'), '', 'xxx', '0 KB', Missing.Value, 'xxx', True, ('admin',), Missing.Value, 'Dexterity Container', DateTime('2015/07/22 15:12:7.787001 GMT+2'), 'xxx', Missing.Value, Missing.Value, Missing.Value, 0, None, (), Missing.Value, Missing.Value, Missing.Value, Missing.Value)
Related
I am using riak2.2.3, and trying to search in a map bucket type, but nothing is ever returned.
I've configured a bucket type "dist_cache" on the memory backend:
# riak-admin bucket-type status dist_cache
dist_cache is active
active: true
allow_mult: true
backend: <<"memory_mult">>
basic_quorum: false
big_vclock: 50
chash_keyfun: {riak_core_util,chash_std_keyfun}
claimant: 'riak#127.0.0.1'
datatype: map
dvv_enabled: true
dw: quorum
last_write_wins: false
linkfun: {modfun,riak_kv_wm_link_walker,mapreduce_linkfun}
n_val: 3
notfound_ok: true
old_vclock: 86400
postcommit: []
pr: 0
precommit: []
pw: 0
r: quorum
rw: quorum
search_index: <<"expirable_token">>
small_vclock: 50
w: quorum
young_vclock: 20
I've then enable search in /etc/riak/:
search = on
Then I have configured an index, with the default schema and associated it with the bucket type (see above).
I can successfully store and retrieve values, using keys, in that bucket. I have stored 3 values in registers: binary data, integer (timestamp) and a string:
[
{{"attrs", :register}, <<131, 97, 111>>},
{{"iat_i", :register}, "1540923453"},
{{"test_s", :register}, "paul"}
]
(displayed after formatting from Elixir shell, using Elixir's Riak library.)
However, nothing is found when I try searching these values:
iex(74)> :riakc_pb_socket.search(pid, "expirable_token", "iat_i:[0 TO *]")
{:ok, {:search_results, [], 0.0, 0}}
iex(75)> :riakc_pb_socket.search(pid, "expirable_token", "iat_i:1540923453")
{:ok, {:search_results, [], 0.0, 0}}
iex(76)> :riakc_pb_socket.search(pid, "expirable_token", "test_s:paul")
{:ok, {:search_results, [], 0.0, 0}}
iex(77)> :riakc_pb_socket.search(pid, "expirable_token", "test_s:*")
{:ok, {:search_results, [], 0.0, 0}}
In addition, /var/log/riak/solr.log doesn't show any error message for these requests.
Am I missing something?
I needed to remove a few options from the java startup options, but now it seems java is up and running, and solr.log does show error message when trying malformed request.
EDIT:
After trying #vempo's solutions:
I have suffixed the field with _register, however it still does not work. Here is how the field is:
iex(12)> APISexAuthBearerCacheRiak.get("ddd", opts)
[
{{"attrs", :register}, <<131, 98, 0, 0, 1, 188>>},
{{"iat_i", :register}, "1542217847"},
{{"test_flag", :flag}, true},
{{"test_register", :register}, "pierre"}
]
but the search request still returns no result:
iex(15)> :riakc_pb_socket.search(pid, "expirable_token", "test_register:*")
{:ok, {:search_results, [], 0.0, 0}}
iex(16)> :riakc_pb_socket.search(pid, "expirable_token", "test_register:pierre")
{:ok, {:search_results, [], 0.0, 0}}
iex(17)> :riakc_pb_socket.search(pid, "expirable_token", "test_register:*")
{:ok, {:search_results, [], 0.0, 0}}
iex(18)> :riakc_pb_socket.search(pid, "expirable_token", "test_flag:true")
{:ok, {:search_results, [], 0.0, 0}}
iex(19)> :riakc_pb_socket.search(pid, "expirable_token", "test_flag:*")
Still know output in /var/log/riak/solr.log, and index seems correctly setup:
iex(14)> :riakc_pb_socket.list_search_indexes(pid)
{:ok,
[
[index: "expirable_token", schema: "_yz_default", n_val: 3],
[index: "famous", schema: "_yz_default", n_val: 3]
]}
For searching within maps the rules are different. According to Searching with Data Types, there are four schemas for maps, one for each embedded type:
*_flag
*_counter
*_register
*_set
So that in your case you should be searching attrs_register, iat_i_register, and test_s_register.
As a side note, the suffixes _s and _i are probably redundant. They are used by the default schema to decide the type of a regular field, but are useless with embedded datatypes).
UPDATE
And to sum up the rules:
a flag field named test will be indexed as test_flag (query test_flag:*)
a register field named test will be indexed as test_register (query test_register:*)
a counter field named test will be indexed as test_counter (query test_counter:*)
a set field named test will be indexed as test_set (query test_set:*)
This is nicely shown in the table in Searching with Data Types: Embedded Schemas.
See also the definition of dynamic fields for embedded datatypes in the default schema, section <!-- Riak datatypes embedded fields -->.
After applying the Plone security patch 20161129 our PloneFormGen form does not work anymore, because it contains Umlauts (ä, ö, ß or €). We use PloneFormGen 1.7.20 which is the recommended version for Plone 4.3.9. Here's the stacktrace:
Module zope.tales.tales, line 696, in evaluate
- URL: file:/var/plone/buildout-cache/eggs/Products.PloneFormGen-1.7.20-py2.7.egg/Products/PloneFormGen/skins/PloneFormGen/widget_fieldset_start.pt
- Line 25, Column 10
- Expression: <PythonExpr widget.Description(here)>
- Names:
{'container': <PloneSite at /mysite>,
'context': <FormFolder at /mysite/mitglied-werden>,
'desitelt': <object object at 0x7fe244f734b0>,
'here': <FormFolder at /mysite/mitglied-werden>,
'loop': {u'field': <Products.PageTemplates.Expressions.PathIterator object at 0x16fe5350>},
'nothing': None,
'options': {'args': (),
'state': <Products.CMFFormController.ControllerState.ControllerState object at 0x7fe22c676610>},
'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x1d61fc00>,
'request': <HTTPRequest, URL=https://www.example.org/mitglied-werden/fg_base_view_p3>,
'root': <Application at >,
'template': <FSControllerPageTemplate at /mysite/fg_base_view_p3 used for /mysite/mitglied-werden>,
'traverse_subpath': [],
'user': <PloneUser 'siteb390'>}
Module Products.PageTemplates.ZRPythonExpr, line 48, in __call__
- __traceback_info__: widget.Description(here)
Module PythonExpr, line 1, in <expression>
Module Products.PloneFormGen.content.field_utils, line 27, in wDescription
Module zope.i18n, line 107, in translate
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 20: ordinal not in range(128)
After removing the umlauts it works again, but the form looks a bit unprofessional now.
After searching the web for one hour now for just this error, I have no particular idea which extension causes this (PloneFormGen?) causes this and how to fix it :-/ Even no idea on which direction to look further...
Starting with 1.7.20, all PFG description fields are pushed through the translation mechanism. (Please don't ask me why they do that with user-supplied fields, because the description field is not language-insensitive in the first place.) Ths imposes additional limitations on what letters you can use in the description, as you have found.
Not claiming that this is a bugfix, but in my quick trial, modifying buildout-cache/eggs/Products.PloneFormGen-1.7.20-py2.7.egg/Products/PloneFormGen/content/field_utils.py line 27 from
if value:
value = translate(value, context=instance.REQUEST)
return cgi.escape(value)
to
if value:
value = translate(value.decode('utf-8'), context=instance.REQUEST)
return cgi.escape(value)
made the problem go away.
I've created a custom content type derived from document. I am trying to use CMIS to query my Alfresco server (tried with 4.2.b and 4.2.c) programmatically for my documents using python cmislib. I have a pyramid server that takes REST calls and sends them to my Alfresco server using CMIS.
I get this error:
2013-04-11 11:19:25,526 | ERROR | Exception when serving /access_manager/search_noauth
Traceback (most recent call last):
File "/home/hbrown/.virtualenvs/access_manager_master/local/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/channel.py", line 329, in service
task.service()
[...]
File "/home/hbrown/workspace/spt/access_manager/access_manager/views/search.py", line 223, in cmis_main
for result in repo.query(whole_query)
File "/home/hbrown/.virtualenvs/access_manager_master/local/lib/python2.7/site-packages/cmislib/model.py", line 2467, in getContentStream
assert(len(contentElements) == 1), 'Expected to find exactly one atom:content element.'
AssertionError: Expected to find exactly one atom:content element.
I am using getContentStream() to retrieve content. Based on the code comment, I'd say it is the correct API call:
>>> doc.getName()
u'sample-b.pdf'
>>> o = open('tmp.pdf', 'wb')
>>> result = doc.getContentStream()
>>> o.write(result.read())
>>> result.close()
>>> o.close()
>>> import os.path
>>> os.path.getsize('tmp.pdf')
117248
The python code in cmislib clearly expects the document to have XML that includes an element named content, and mine does not.
The calling code looks like this:
from cmislib import CmisClient
SERVER = "localhost"
url = "http://{0}:8080/alfresco/cmisatom".format(SERVER)
client = CmisClient(url, 'admin', 'alfresco')
repo = client.defaultRepository
results = repo.query("select * from wg:bulletin")
print results[0].getContentStream().read()
The XML being operated on in getContentStream looks like this:
<atom:entry>
<atom:author>
<atom:name/>
</atom:author>
<atom:id>http://chemistry.apache.org/aWQtMQ==</atom:id>
<atom:published>2013-04-12T03:22:38Z</atom:published>
<atom:title>Query Result id-1</atom:title>
<app:edited>2013-04-12T03:22:38Z</app:edited>
<atom:updated>2013-04-12T03:22:38Z</atom:updated>
<cmisra:object xmlns:ns3="http://docs.oasis-open.org/ns/cmis/messaging/200908/">
<cmis:properties>
<cmis:propertyInteger displayName="Content Stream Length" localName="contentStreamLength" propertyDefinitionId="cmis:contentStreamLength" queryName="b.cmis:contentStreamLength">
<cmis:value>249</cmis:value>
</cmis:propertyInteger>
<cmis:propertyId displayName="Object Type Id" localName="objectTypeId" propertyDefinitionId="cmis:objectTypeId" queryName="b.cmis:objectTypeId">
<cmis:value>D:wg:bulletin</cmis:value>
</cmis:propertyId>
<cmis:propertyString displayName="Version Series Checked Out By" localName="versionSeriesCheckedOutBy" propertyDefinitionId="cmis:versionSeriesCheckedOutBy" queryName="b.cmis:versionSeriesCheckedOutBy"/>
<cmis:propertyId displayName="Version Series Checked Out Id" localName="versionSeriesCheckedOutId" propertyDefinitionId="cmis:versionSeriesCheckedOutId" queryName="b.cmis:versionSeriesCheckedOutId"/>
<cmis:propertyId displayName="Version series id" localName="versionSeriesId" propertyDefinitionId="cmis:versionSeriesId" queryName="b.cmis:versionSeriesId">
<cmis:value>workspace://SpacesStore/1cd2053d-1fc4-4e85-b780-ba80284f0841</cmis:value>
</cmis:propertyId>
<cmis:propertyString displayName="wg:account" localName="account" propertyDefinitionId="wg:account" queryName="b.wg:account"/>
<cmis:propertyString displayName="Version Label" localName="versionLabel" propertyDefinitionId="cmis:versionLabel" queryName="b.cmis:versionLabel">
<cmis:value>1.0</cmis:value>
</cmis:propertyString>
<cmis:propertyBoolean displayName="Is Latest Version" localName="isLatestVersion" propertyDefinitionId="cmis:isLatestVersion" queryName="b.cmis:isLatestVersion">
<cmis:value>true</cmis:value>
</cmis:propertyBoolean>
<cmis:propertyBoolean displayName="Is Version Series Checked Out" localName="isVersionSeriesCheckedOut" propertyDefinitionId="cmis:isVersionSeriesCheckedOut" queryName="b.cmis:isVersionSeriesCheckedOut">
<cmis:value>false</cmis:value>
</cmis:propertyBoolean>
<cmis:propertyString displayName="Last Modified By" localName="lastModifiedBy" propertyDefinitionId="cmis:lastModifiedBy" queryName="b.cmis:lastModifiedBy">
<cmis:value>admin</cmis:value>
</cmis:propertyString>
<cmis:propertyString displayName="Created by" localName="createdBy" propertyDefinitionId="cmis:createdBy" queryName="b.cmis:createdBy">
<cmis:value>admin</cmis:value>
</cmis:propertyString>
<cmis:propertyDateTime displayName="wg:displayUntil" localName="displayUntil" propertyDefinitionId="wg:displayUntil" queryName="b.wg:displayUntil"/>
<cmis:propertyId displayName="Alfresco Node Ref" localName="nodeRef" propertyDefinitionId="alfcmis:nodeRef" queryName="b.alfcmis:nodeRef">
<cmis:value>workspace://SpacesStore/1cd2053d-1fc4-4e85-b780-ba80284f0841</cmis:value>
</cmis:propertyId>
<cmis:propertyString displayName="wg:email" localName="email" propertyDefinitionId="wg:email" queryName="b.wg:email"/>
<cmis:propertyBoolean displayName="wg:isActive" localName="isActive" propertyDefinitionId="wg:isActive" queryName="b.wg:isActive">
<cmis:value>false</cmis:value>
</cmis:propertyBoolean>
<cmis:propertyString displayName="wg:username" localName="username" propertyDefinitionId="wg:username" queryName="b.wg:username"/>
<cmis:propertyBoolean displayName="Is Latest Major Version" localName="isLatestMajorVersion" propertyDefinitionId="cmis:isLatestMajorVersion" queryName="b.cmis:isLatestMajorVersion">
<cmis:value>true</cmis:value>
</cmis:propertyBoolean>
<cmis:propertyId displayName="Content Stream Id" localName="contentStreamId" propertyDefinitionId="cmis:contentStreamId" queryName="b.cmis:contentStreamId">
<cmis:value>store://2013/4/10/15/29/20b185d0-afae-4a7f-a06e-58eab399bdc9.bin</cmis:value>
</cmis:propertyId>
<cmis:propertyString displayName="Name" localName="name" propertyDefinitionId="cmis:name" queryName="b.cmis:name">
<cmis:value>.pythonrc</cmis:value>
</cmis:propertyString>
<cmis:propertyString displayName="Content Stream MIME Type" localName="contentStreamMimeType" propertyDefinitionId="cmis:contentStreamMimeType" queryName="b.cmis:contentStreamMimeType">
<cmis:value>text/plain</cmis:value>
</cmis:propertyString>
<cmis:propertyDateTime displayName="Creation Date" localName="creationDate" propertyDefinitionId="cmis:creationDate" queryName="b.cmis:creationDate">
<cmis:value>2013-04-10T15:29:18.146-04:00</cmis:value>
</cmis:propertyDateTime>
<cmis:propertyString displayName="Change token" localName="changeToken" propertyDefinitionId="cmis:changeToken" queryName="b.cmis:changeToken"/>
<cmis:propertyString displayName="wg:state" localName="state" propertyDefinitionId="wg:state" queryName="b.wg:state"/>
<cmis:propertyDateTime displayName="wg:displayFrom" localName="displayFrom" propertyDefinitionId="wg:displayFrom" queryName="b.wg:displayFrom"/>
<cmis:propertyString displayName="Checkin Comment" localName="checkinComment" propertyDefinitionId="cmis:checkinComment" queryName="b.cmis:checkinComment"/>
<cmis:propertyString displayName="wg:application" localName="application" propertyDefinitionId="wg:application" queryName="b.wg:application"/>
<cmis:propertyId displayName="Object Id" localName="objectId" propertyDefinitionId="cmis:objectId" queryName="b.cmis:objectId">
<cmis:value>workspace://SpacesStore/1cd2053d-1fc4-4e85-b780-ba80284f0841;1.0</cmis:value>
</cmis:propertyId>
<cmis:propertyBoolean displayName="Is Immutable" localName="isImmutable" propertyDefinitionId="cmis:isImmutable" queryName="b.cmis:isImmutable">
<cmis:value>false</cmis:value>
</cmis:propertyBoolean>
<cmis:propertyBoolean displayName="Is Major Version" localName="isMajorVersion" propertyDefinitionId="cmis:isMajorVersion" queryName="b.cmis:isMajorVersion">
<cmis:value>true</cmis:value>
</cmis:propertyBoolean>
<cmis:propertyString displayName="wg:institution" localName="institution" propertyDefinitionId="wg:institution" queryName="b.wg:institution"/>
<cmis:propertyId displayName="Base Type Id" localName="baseTypeId" propertyDefinitionId="cmis:baseTypeId" queryName="b.cmis:baseTypeId">
<cmis:value>cmis:document</cmis:value>
</cmis:propertyId>
<cmis:propertyString displayName="Content Stream Filename" localName="contentStreamFileName" propertyDefinitionId="cmis:contentStreamFileName" queryName="b.cmis:contentStreamFileName">
<cmis:value>.pythonrc</cmis:value>
</cmis:propertyString>
<cmis:propertyDateTime displayName="Last Modified Date" localName="lastModificationDate" propertyDefinitionId="cmis:lastModificationDate" queryName="b.cmis:lastModificationDate">
<cmis:value>2013-04-10T15:29:23.384-04:00</cmis:value>
</cmis:propertyDateTime>
</cmis:properties>
</cmisra:object>
</atom:entry>
There is clearly no XML element named content here for the python code to extract.
Is this a misconfiguration of my custom content document or is it a change in CMIS that cmislib does not track or am I calling the wrong API function to get the content or something else?
Later: the minimum change to fix this is to make calls to either reload or getAllowableActions.
This was the original code:
def cmis_main(props, settings):
"""
Create a CMIS query based on props and execute against Alfresco
"""
def cmis_query(props, mapping):
"""
Create CMIS query of AND-separated OR-clauses
"""
# Code that formats a query string from dictionaries...
cmis_mapping = {
# Dictionary config for call to cmis_query
# Nothing to see here. Move on.
"app_sids": {
"where_fmt": IN_WHERE_FMT,
"key": "{0}:application".format(CMIS_NAMESPACE),
"fn": set_format,
},
}
cmis_url, cmis_user, cmis_password = cmis_args(settings)
cmisclient = CmisClient(cmis_url, cmis_user, cmis_password)
repo = cmisclient.getDefaultRepository()
whole_query = cmis_query(props, cmis_mapping)
logger.debug(whole_query)
return [
{
'name': result.name,
'content': result.getContentStream().read(),
'content_mime_type': result.properties["cmis:contentStreamMimeType"],
}
for result in repo.query(whole_query)
]
And it was broken. So I changed the code to this:
results = list(repo.query(whole_query))
for result in results:
print(result.getAllowableActions())
# or: result.reload()
return [
{
'name': result.name,
'content': result.getContentStream().read(),
'content_mime_type': result.properties["cmis:contentStreamMimeType"],
}
for result in results
]
And it worked. I changed it to this:
results = list(repo.query(whole_query))
for result in results:
pass
return [
{
'name': result.name,
'content': result.getContentStream().read(),
'content_mime_type': result.properties["cmis:contentStreamMimeType"],
}
for result in results
]
And it broke. So the XML does not appear to be fully loaded in the CMISLIB object.
Try doing results[0].reload() before calling getContentStream(). That shouldn't be required but it may force the object to reload with the content element.
I would like to use R to send requests to the Amazon Product API service.
Is there a way to authenticate and query the Amazon Product API with R without getting the following error:
"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."
Try this
This should perform a search using the Product Advertising API, which I think you mean.
You need to supply the AWSAccessKeyId and AWSsecretkey,
which can be acquired on: http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/GSG/
search.amazon <- function(Keywords, SearchIndex = 'All', AWSAccessKeyId, AWSsecretkey, AssociateTag, ResponseGroup = 'Small', Operation = 'ItemSearch'){
library(digest)
library(RCurl)
base.html.string <- "http://ecs.amazonaws.com/onca/xml?"
SearchIndex <- match.arg(SearchIndex, c('All',
'Apparel',
'Appliances',
'ArtsAndCrafts',
'Automotive',
'Baby',
'Beauty',
'Blended',
'Books',
'Classical',
'DigitalMusic',
'DVD',
'Electronics',
'ForeignBooks',
'Garden',
'GourmetFood',
'Grocery',
'HealthPersonalCare',
'Hobbies',
'HomeGarden',
'HomeImprovement',
'Industrial',
'Jewelry',
'KindleStore',
'Kitchen',
'Lighting',
'Magazines',
'Marketplace',
'Miscellaneous',
'MobileApps',
'MP3Downloads',
'Music',
'MusicalInstruments',
'MusicTracks',
'OfficeProducts',
'OutdoorLiving',
'Outlet',
'PCHardware',
'PetSupplies',
'Photo',
'Shoes',
'Software',
'SoftwareVideoGames',
'SportingGoods',
'Tools',
'Toys',
'UnboxVideo',
'VHS',
'Video',
'VideoGames',
'Watches',
'Wireless',
'WirelessAccessories'))
Operation <- match.arg(Operation, c('ItemSearch',
'ItemLookup',
'BrowseNodeLookup',
'CartAdd',
'CartClear',
'CartCreate',
'CartGet',
'CartModify',
'SimilarityLookup'))
ResponseGroup <- match.arg(ResponseGroup, c('Accessories',
'AlternateVersions',
'BrowseNodeInfo',
'BrowseNodes',
'Cart',
'CartNewReleases',
'CartTopSellers',
'CartSimilarities',
'Collections',
'EditorialReview',
'Images',
'ItemAttributes',
'ItemIds',
'Large',
'Medium',
'MostGifted',
'MostWishedFor',
'NewReleases',
'OfferFull',
'OfferListings',
'Offers',
'OfferSummary',
'PromotionSummary',
'RelatedItems',
'Request',
'Reviews',
'SalesRank',
'SearchBins',
'Similarities',
'Small',
'TopSellers',
'Tracks',
'Variations',
'VariationImages',
'VariationMatrix',
'VariationOffers',
'VariationSummary'),
several.ok = TRUE)
version.request = '2011-08-01'
Service = 'AWSECommerceService'
if(!is.character(AWSsecretkey)){
message('The AWSsecretkey should be entered as a character vect, ie be qouted')
}
pb.txt <- Sys.time()
pb.date <- as.POSIXct(pb.txt, tz = Sys.timezone)
Timestamp = strtrim(format(pb.date, tz = "GMT", usetz = TRUE, "%Y-%m-%dT%H:%M:%S.000Z"), 24)
str = paste('GET\necs.amazonaws.com\n/onca/xml\n',
'AWSAccessKeyId=', curlEscape(AWSAccessKeyId),
'&AssociateTag=', AssociateTag,
'&Keywords=', curlEscape(Keywords),
'&Operation=', curlEscape(Operation),
'&ResponseGroup=', curlEscape(ResponseGroup),
'&SearchIndex=', curlEscape(SearchIndex),
'&Service=AWSECommerceService',
'&Timestamp=', gsub('%2E','.',gsub('%2D', '-', curlEscape(Timestamp))),
'&Version=', version.request,
sep = '')
## signature test
Signature = curlEscape(base64(hmac( enc2utf8((AWSsecretkey)), enc2utf8(str1), algo = 'sha256', serialize = FALSE, raw = TRUE)))
AmazonURL <- paste(base.html.string,
'AWSAccessKeyId=', AWSAccessKeyId,
'&AssociateTag=', AssociateTag,
'&Keywords=', Keywords,
'&Operation=',Operation,
'&ResponseGroup=',ResponseGroup,
'&SearchIndex=', SearchIndex,
'&Service=AWSECommerceService',
'&Timestamp=', Timestamp,
'&Version=', version.request,
'&Signature=', Signature
sep = '')
AmazonResult <- getURL(AmazonURL)
return(AmazonResult)
}
The URL which we get from running this code wont give a signature address. To get a signature address use the following web address and paste the URL over there and click on Display Signed URL.
http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html
See this post as well as Amazon's Signed Requests Helper. This posting, as well as the two links I've shared helped me get up and running with Amazon's Product Advertising API.
I am new and I don't have enough "rep" to comment, but in Micha's answer there needs to be a comma after Signature in this area (I have added the comma):
AmazonURL <- paste(base.html.string,
'AWSAccessKeyId=', AWSAccessKeyId,
'&AssociateTag=', AssociateTag,
'&Keywords=', Keywords,
'&Operation=',Operation,
'&ResponseGroup=',ResponseGroup,
'&SearchIndex=', SearchIndex,
'&Service=AWSECommerceService',
'&Timestamp=', Timestamp,
'&Version=', version.request,
'&Signature=', Signature,
sep = '')
Check http://www.omegahat.org/ . There are several Amazon-related packages there, and even if Product API might not be among these, you should be able to copy the basic functions.
which Amazon Product API you are interested in?
I never saw an interface for the "Product Advertising API"! For AWS you can use the package AWS tools package at CRAN: http://cran.r-project.org/web/packages/AWS.tools/index.html
The following code samples produce the same error when I perform the SAVEAS:
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
filePath = (string.Format("{0}.{1}", Path.GetTempFileName(), "xls"));
...do some stuff to the workbook ...
excelApp.DisplayAlerts = false;
excelApp.ActiveWorkbook.SaveAs(filePath)
OR
Missing m = Missing.Value;
excelApp.ActiveWorkbook.SaveAs(filePath, m, m,m,m,m, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, m,m,m);
OR
excelApp.ActiveWorkbook.SaveAs(filePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value);
Here's the error:
Exception: System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
at Common.CreateTempExcelFile(DataTable data)
I had the Office 2003 interops on the server but have upgraded to 2007. No difference.
Incidentally, I can write a text file to the same file/path so it's not a permissions error on the folder.
Thanks in advance,
Jim
Looks like invalid interop version of Excel was installed.