Cannot load default preferences in Firefox addon - firefox

I'm creating a very simple Firefox addon for testing purposes. I want to set default preferences (e.g. set extensions.myextension.bingo to "http://www.example.com"), however I can't seem to get this to work.
Here's what I did so far:
My lib/main.js looks like this:
var {Cc, Ci} = require("chrome");
var prefs = Cc["#mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.myextension.");
var value = prefs.getCharPref("bingo");
console.log("found: " + value);
My defaults/preferences/prefs.js file looks like this:
pref("extensions.myextension.bingo", "http://www.example.com");
When I run "cfx test" in the command line, I see this:
(D:\Users\myuser\addon-sdk-1.16) D:\Users\myuser\Projects\ffaddontest>cfx test
Using binary at 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'.
Using profile at 'd:\users\myuser\appdata\local\temp\tmpd_6h4q.mozrunner'.
Running tests on Firefox 31.0/Gecko 31.0 ({ec8030f7-c20a-464f-9b0e-13a3a9e97384}) under winnt/x86.
Error: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getCharPref]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///d:/users/myuser/appdata/local/temp/tmpd_6h4q.mozrunner/extensions/jid1-LtJU5H9I2NHnBA#jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-ltju5h9i2nhnba-at-jetpack/ffaddontest/lib/main.js :: <TOP_LEVEL> :: line 4" data: no]
Traceback (most recent call last):
File "resource://gre/modules/commonjs/sdk/loader/cuddlefish.js", line 129, in CuddlefishLoader/options<.load
result = load(loader, module);
File "resource://jid1-ltju5h9i2nhnba-at-jetpack/ffaddontest/tests/test-main.js", line 1, in
var main = require("./main");
File "resource://gre/modules/commonjs/sdk/loader/cuddlefish.js", line 129, in CuddlefishLoader/options<.load
result = load(loader, module);
File "undefined", line 4, in
0 of 1 tests passed.
JavaScript strict warning: chrome://browser/content/urlbarBindings.xml, line 692: reference to undefined property this._value
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 674: aUrl is undefined
Total time: 1.966000 seconds
Program terminated unsuccessfully.
Apparently the preference is not set (I don't see it in about:config either when running "cfx run" or creating and loading an xpi file using "cfx xpi").
What is it that I am doing wrong?
Thank you for your response.

Related

ADSError 857212673: Can't read variable values through name (pyads)

I've been having a problem lately where I can't access the value of any variable through their name. It's not a connection problem since I can read the value from the read() function just fine. However whenever I use the read_by_name function there's always the same error pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).
Because it's an unknown error I haven't been able to find documentation on it. I'm using a BC9120 as a PLC and TwinCat 2. Does anyone know what might be causing this?
Code:
if self.plc.is_open == False:
self.plc.open()
print(self.plc.read(pyads.INDEXGROUP_MEMORYBIT, 0*8 + 0, pyads.PLCTYPE_BOOL))
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
Logs:
False
Traceback (most recent call last):
File "c:\Users\MAP9AV\Documents\Banca\Modelo Preditivo\Thread_Sup.py", line 50, in run
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\connection.py", line 540, in read_by_name
return adsSyncReadByNameEx(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 1154, in adsSyncReadByNameEx
handle = adsGetHandle(port, address, data_name)
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 890, in adsGetHandle
handle = adsSyncReadWriteReqEx2(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 774, in adsSyncReadWriteReqEx2
raise ADSError(err_code)
pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).

Why do I get credential read in error on google slide API?

I downloaded the gsuite developers python code from :
(https://github.com/gsuitedevs/python-samples)
I then enabled api access and downloaded the credentials.json file and ran the quickstart.py in:
(python-samples-master/slides/quickstart) and it worked and outputted
The presentation contains 5 slides:
- Slide #1 contains 4 elements.
- Slide #2 contains 11 elements.
- Slide #3 contains 9 elements.
- Slide #4 contains 5 elements.
- Slide #5 contains 12 elements.
So it worked. Then I tried to run test_snippets.py in:
(python-samples-master/slides/snippets)
And I get an error
======================================================================
ERROR: setUpClass (__main__.SnippetsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1228, in _implicit_credentials_from_files
credentials_filename)
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1397, in _get_application_default_credential_from_file
AUTHORIZED_USER + "' or '" + SERVICE_ACCOUNT + "' values)")
oauth2client.client.ApplicationDefaultCredentialsError: 'type' field should be defined (and have one of the 'authorized_user' or 'service_account' values)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_snippets.py", line 32, in setUpClass
super(SnippetsTest, cls).setUpClass()
File "~/Desktop/python-samples-master/slides/snippets/base_test.py", line 27, in setUpClass
cls.credentials = cls.create_credentials()
File "~/Desktop/python-samples-master/slides/snippets/base_test.py", line 44, in create_credentials
credentials = GoogleCredentials.get_application_default()
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1271, in get_application_default
return GoogleCredentials._get_implicit_credentials()
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1256, in _get_implicit_credentials
credentials = checker()
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1231, in _implicit_credentials_from_files
extra_help, error)
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1429, in _raise_exception_for_reading_json
credential_file + extra_help + ': ' + str(error))
oauth2client.client.ApplicationDefaultCredentialsError: An error was encountered while reading json file: ~/Documents/credentials/credentials.json (pointed to by GOOGLE_APPLICATION_CREDENTIALS environment variable): 'type' field should be defined (and have one of the 'authorized_user' or 'service_account' values)
I definitely have a GOOGLE_APPLICATION_CREDENTIALS that points to the same credentials that successfully ran quickstart.py.
Is there something else I need or do I need to change some code to load the credentials data in?
It seems like GoogleCredentials.get_application_default() call is the one that is erroring
def create_credentials(cls):
credentials = GoogleCredentials.get_application_default()
scope = [
'https://www.googleapis.com/auth/drive',
]
return credentials.create_scoped(scope)
The file pointed to the environment variable GOOGLE_APPLICATION_CREDENTIALS is not a valid service account json file.
Open your service account json file. The beginning of the file should look similar to this:
{
"type": "service_account",
"project_id": "development-123456",
"private_key_id": "19c38bac6560abcdef01234567ac4da7991cbaad",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANB

why i keep having the same error in that code

i'm following a tutorial course i'm trying to make a web application in python 3.7 that see if there is any bad words in a text file
the text file contains the following text :
-- Houston, we have a problem. (Apollo 13)
-- Mama always said, life is like a box of chocolates. You never know what you are going to get. (Forrest Gump)
-- You cant handle the truth. (A Few Good Men)
-- I believe everything and I believe nothing. (A Shot in the Dark)
import urllib.request
def read_text():
quotes = open (r'C:\Users\M\Desktop\TEMP FILES\movie_quotes.txt')
content_of_file = quotes.read()
print(content_of_file)
quotes.close()
check_profanity(content_of_file)
def check_profanity(text):
connection = urllib.request.urlopen( 'http://www.wdylike.appspot.com/?q='+text)
output = connection.read()
print(output)
connection.close()
read_text()
and i have that error :
Traceback (most recent call last):
File "C:\Users\Mosa Abbas\Desktop\TEMP FILES\ipnd-starter-code-master\ipnd-starter-code-master\stage_3\lesson_3.3_classes\c_profanity_editor\check_profanity.py", line 32, in <module>
read_text()
File "C:\Users\Mosa Abbas\Desktop\TEMP FILES\ipnd-starter-code-master\ipnd-starter-code-master\stage_3\lesson_3.3_classes\c_profanity_editor\check_profanity.py", line 23, in read_text
check_profanity(content_of_file)
File "C:\Users\Mosa Abbas\Desktop\TEMP FILES\ipnd-starter-code-master\ipnd-starter-code-master\stage_3\lesson_3.3_classes\c_profanity_editor\check_profanity.py", line 27, in check_profanity
connection = urllib.request.urlopen( 'http://www.wdylike.appspot.com/?q='+text)
File "C:\Users\Mosa Abbas\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Mosa Abbas\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\Mosa Abbas\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\Mosa Abbas\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\Mosa Abbas\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\Mosa Abbas\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
what is that error and what i should do to get rid of it
urllib.error.HTTPError: HTTP Error 400: Bad Request
i'v tried to add this line of code :
url = 'http://www.wdylike.appspot.com/?q='+urllib.parse.quote(text, safe = '/')
and then:
connection = urllib.request.urlopen(url)
and i got
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
i'm a beginner in python and programming web applications so please help :(
When sending a HTTP request through a GET method, it is necessary to escape the GET vars.
So you should probably escape your text before appending it to the URL.
Have a look to question #1695183
i found the solution
I think that happens be because i'm not encoding the string before appending it to the url.
in python3 we should do the following to 'text' before appending it to the url:
text_to_check = urllib.parse.quote_plus(text)
Python2 would be something like this
(urllib was broken into smaller components in python3):
text_to_check = urllib.quote_plus(text_to_check)
This means that, when appending a string with whitespace to the url it will appear as something like "Am+I+cursing%3F" instead of "Am I cursing?".
Full check_profanity() example:
def check_profanity(text_to_check):
text_to_check = urllib.parse.quote_plus(text_to_check)
connection = urlopen(
"http://www.wdylike.appspot.com/?q=" + text_to_check)
output = connection.read()
print(output)
connection.close()

bypass untrusted sites with selenium3

I am stuck for good. I use the python client of selenium3.0 with Mozilla Firefox 49.0.2 and phantomjs 2.1.1.
the problem is that the site has not valid certificates thus it is stuck in a page "Your connection is not secure". i cant remember what was different before but this used to work with the following code
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
profile.assume_untrusted_cert_issuer = False
profile.set_preference("network.proxy.no_proxies_on","localhost,127.0.0.1,"+url)
driver = webdriver.Firefox(profile)
drive.get('https://'+url'+'port)
but not anymore. i should have upgraded Firefox in some point. Btw the error is
Traceback (most recent call last):
File "seleniumtest.py", line 75, in <module>
open_browser(url,port,"user","rZMBlg4ZpOX")
File "seleniumtest.py", line 52, in open_browser
driver.get(g)
File "/home/iob/Envs/selenium/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 248, in get
self.execute(Command.GET, {'url': url})
File "/home/iob/Envs/selenium/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/home/iob/Envs/selenium/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 196, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Error loading page
I found that Firefox uses marionette as the default FirefoxDriver since F38, i think. i dont know if this has to do anything with the problem. I tried to debug the issue and see the response. i found that the response is like that:
{u'sessionId': u'7334d50d-f188-4c70-be4e-3d1440cf21ec', u'value': {u'processId': 32334, u'browserVersion': u'49.0.2', u'takesScreenshot': True, u'acceptSslCerts': False, u'appBuildId': u'20161025170400', u'XULappId': u'{ec8030f7-c20a-464f-9b0e-13a3a9e97384}', u'javascriptEnabled': True, u'raisesAccessibilityExceptions': False, u'specificationLevel': 0, u'platform': u'LINUX', u'browserName': u'firefox', u'version': u'', u'proxy': {}, u'marionette': True, u'rotatable': False, u'device': u'desktop', u'takesElementScreenshot': True, u'platformName': u'linux', u'platformVersion': u'4.4.0-47-generic', u'command_id': 1}
i noticed u'acceptSslCerts': False so i thought that this is what I need to set for it to work. But I am not sure how exactly and whatever I tried doesnt seem to work (ex: capabilities["acceptSslCerts"]= True)
With phantomjs i use the code below
service_args = ['--proxy=https://10.241.226.200:5601',
'--proxy-type=https',
'--proxy-auth='+username+':'+password,
'--ignore-ssl-errors=true', '--ssl-protocol=any']
driver=webdriver.PhantomJS(service_args=service_args)
driver.get("https://"+url+":"+port)
That doesnt raise any error but neither returns the title so i assume that something is wrong and it didnt open the link properly.
Any idea? Any link for elaboration would be helpful

Accessing portal_registry via plone.app.theming

I'm trying to use a parameter expression in the plone.app.theming theming-controlpanel that gets a value from the portal_registry to use within the rules.xml file of the theme.
The goal is that if a boolean is set in the registry, the theme can allow/disallow certain content.
So my parameter expression (in theming-controlpanel) is
enable_ad_tags = python:context.portal_registry['lw.portal.enableadtags']
There is a corresponding boolean field in the portal_registry.
The rules.xml file has this rule:
<!-- Global Ad Tags -->
<drop css:theme="#globalAdTags" if="not($enable_ad_tags)" />
The problem is that on my local machine i get this error in the console all the time:
c2014-08-08 09:49:19 ERROR plone.transformchain Unexpected error whilst trying to apply transform chain
Traceback (most recent call last):
File "/Users/aaronwilliams/.buildout/eggs/plone.transformchain-1.0.3-py2.7.egg/plone/transformchain/transformer.py", line 48, in __call__
newResult = handler.transformIterable(result, encoding)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/transform.py", line 179, in transformIterable
params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/utils.py", line 630, in prepareThemeParameters
params[name] = quote_param(expression(expressionContext))
File "/Users/aaronwilliams/.buildout/eggs/Zope2-2.13.20-py2.7.egg/Products/PageTemplates/ZRPythonExpr.py", line 48, in __call__
return eval(self._code, vars, {})
File "PythonExpr", line 1, in <expression>
File "/Users/aaronwilliams/.buildout/eggs/AccessControl-3.0.6-py2.7-macosx-10.8-x86_64.egg/AccessControl/ImplPython.py", line 675, in guarded_getattr
v = getattr(inst, name)
AttributeError: 'DirectoryResource' object has no attribute 'portal_registry'
Is there a problem with the pattern I am trying to use here?
Is there a better/safer way to achieve this?
Using portal instead of context works:
enable_ad_tags = python:portal.portal_registry['lw.portal.enableadtags']
IMHO context should also work, or context does not behave like it does, or the naming is wrong.

Resources