What does Jython need for SimpleXMLRPCServer to work? - jython

I tried the first example from the python documentation for SimpleXMLRPCServer.
It works perfectly fine in python, but when I try it using jython I get the following
stacktrace:
Traceback (most recent call last):
File "sampleclient.py", line 4, in <module>
print s.pow(2,3) # Returns 2**3 = 8
File "/usr/share/jython/Lib/xmlrpclib.py", line 1147, in __call__
return self.__send(self.__name, args)
File "/usr/share/jython/Lib/xmlrpclib.py", line 1433, in _ServerProxy__request
response = self.__transport.request(
File "/usr/share/jython/Lib/xmlrpclib.py", line 1201, in request
return self._parse_response(h.getfile(), sock)
File "/usr/share/jython/Lib/xmlrpclib.py", line 1324, in _parse_response
p, u = self.getparser()
File "/usr/share/jython/Lib/xmlrpclib.py", line 1210, in getparser
return getparser(use_datetime=self._use_datetime)
File "/usr/share/jython/Lib/xmlrpclib.py", line 1023, in getparser
parser = ExpatParser(target)
File "/usr/share/jython/Lib/xmlrpclib.py", line 536, in __init__
self._parser = parser = expat.ParserCreate(None, None)
File "/usr/share/jython/Lib/xml/parsers/expat.py", line 63, in ParserCreate
return XMLParser(encoding, namespace_separator)
File "/usr/share/jython/Lib/xml/parsers/expat.py", line 91, in __init__
self._reader = XMLReaderFactory.createXMLReader(_xerces_parser)
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:229)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:220)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
I'm much more experienced with python than java, so I'm not sure how to fix this. Is a dependency missing from my system or do I need to fiddle with classpaths?
EDIT: I re-tried this with the stand-alone versions from Jython's website, and they worked, so It seems there might be something broken with Ubuntu's installed version?

Related

Django tests pass locally but not on Github Actions push

My tests pass locally and in fact on Github Actions it also says "ran 8 tests" and then "OK" (and I have 8). However, the test stage fails due to a strange error in the traceback.
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 421, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "SCHEMA": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/work/store/store/manage.py", line 22, in <module>
main()
File "/home/runner/work/store/store/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/commands/test.py", line 55, in handle
failures = test_runner.run_tests(test_labels)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/test/runner.py", line 736, in run_tests
self.teardown_databases(old_config)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django_heroku/core.py", line 41, in teardown_databases
self._wipe_tables(connection)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django_heroku/core.py", line 26, in _wipe_tables
cursor.execute(
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 421, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "SCHEMA": syntax error
Error: Process completed with exit code 1.
These are all just default Django files and I haven't messed with any of them. I don't really know what to do about it and internet searches yield nothing helpful.
Just had the same issue. For me I had django_heroku in my project settings.py. It looks like, based on the comments that your app is using this.
I had something like this in settings.py:
import django_heroku
django_heroku.settings(locals())
change to the following so it doesn't use django_heroku on github actions:
if os.environ.get('ENVIRONMENT') != 'github':
import django_heroku
django_heroku.settings(locals())
and then declare an environment variable in the workflow file, I have this:
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']
env:
DJANGO_SECRET_KEY: "someKey"
ENVIRONMENT: github
Note: this is assuming you have environment variables setup. I know there are different ways of doing it, so depending on how they are setup you might have to change how they are accessed
more info here
edit:
As per the comments, you don't have to declare an additional environment variable because github has a default variable called GITHUB_ACTIONS
so you can do
if os.environ.get('GITHUB_ACTIONS') != 'true':
import django_heroku
django_heroku.settings(locals())

Unable to load web page with seleniumwire

Unable to load the web page using seleniumwire, I am observing this error in the browser.
This page isn't working
xxx.xyz didn't send any data.
ERR_EMPTY_RESPONSE
When I replace seleniumwire with selenium while initializing the webdriver, the issue is no longer observed.
Seleniumwire was working fine and the below-mentioned error started occurring a couple of days ago.
Seleniumwire version: 4.4.0
Python 3.9
MacOS Big Sur
AttributeError: module 'lib' has no attribute 'SSL_CTX_get0_param'
ERROR:seleniumwire.server:127.0.0.1:61095: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/server.py",
line 113, in handle root_layer() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/modes/http_proxy.py",
line 9, in call layer() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/tls.py",
line 285, in call layer() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/http1.py",
line 100, in call layer() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/http.py",
line 206, in call if not self._process_flow(flow): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/http.py",
line 285, in _process_flow return self.handle_regular_connect(f) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/http.py",
line 224, in handle_regular_connect layer() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/tls.py",
line 278, in call self._establish_tls_with_client_and_server() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/tls.py",
line 358, in _establish_tls_with_client_and_server self._establish_tls_with_server() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/tls.py",
line 445, in _establish_tls_with_server self.server_conn.establish_tls( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/connections.py",
line 295, in establish_tls self.convert_to_tls(cert=client_cert, sni=sni, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/net/tcp.py",
line 382, in convert_to_tls context = tls.create_client_context( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/seleniumwire/thirdparty/mitmproxy/net/tls.py",
line 285, in create_client_context param = SSL._lib.SSL_CTX_get0_param(context._context)
AttributeError: module 'lib' has no attribute 'SSL_CTX_get0_param'
This looks like you are using an outdated version of the cryptography library.

Accessing files in S3 bucket from pyspark

I am trying to access a file stored in the S3 bucket from pyspark code. It is giving me the attached error message.
The program works fine when working with files stored locally.
I tried using s3://, s3a:// and s3n:// but none of them seems to work.
code:
ACCESS_KEY = "*********"
SECRET_KEY = "**********"
EncodedSecretKey = SECRET_KEY.replace("/", "%2F")
s3url="s3n://"+ACCESS_KEY+":"+EncodedSecretKey+"#"+bucket_name+"/"+file_name
sqlContext.read.option("delimiter",delimiter).load(s3url,
format='com.databricks.spark.csv',
header='true',
inferSchema='true')
Error Message
Traceback (most recent call last):
File "C:\Users\sachari\AppData\Local\Temp\zeppelin_pyspark-5481670497409059953.py", line 367, in <module>
raise Exception(traceback.format_exc())
Exception: Traceback (most recent call last):
File "C:\Users\sachari\AppData\Local\Temp\zeppelin_pyspark-5481670497409059953.py", line 355, in <module>
exec(code, _zcUserQueryNameSpace)
File "<stdin>", line 14, in <module>
File "<stdin>", line 10, in get_df
File "C:\zeppelin\interpreter\spark\pyspark\pyspark.zip\pyspark\sql\readwriter.py", line 149, in load
return self._df(self._jreader.load(path))
File "C:\zeppelin\interpreter\spark\pyspark\py4j-0.10.4-src.zip\py4j\java_gateway.py", line 1133, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "C:\zeppelin\interpreter\spark\pyspark\pyspark.zip\pyspark\sql\utils.py", line 63, in deco
return f(*a, **kw)
File "C:\zeppelin\interpreter\spark\pyspark\py4j-0.10.4-src.zip\py4j\protocol.py", line 319, in get_return_value
format(target_id, ".", name), value)
Py4JJavaError: An error occurred while calling o537.load.
: java.io.IOException: No FileSystem for scheme: s3n
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2584)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2591)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:91)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2630)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2612)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:370)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:296)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:372)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:370)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
at scala.collection.immutable.List.flatMap(List.scala:344)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:370)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Unknown Source)
you have to load aws package,
for pyspark shell you have to load the package as below and it's also work into spark-submit command.
pyspark --packages org.apache.hadoop:hadoop-aws:2.7.1
or
you have to set credentials as shown in below link.
https://hadoop.apache.org/docs/r2.7.2/hadoop-aws/tools/hadoop-aws/index.html

Twitsted ValueError: Unknown ECC curve on Raspian Stretch

I want to use my Raspberry Pi 3, running Rapian Stretch for a web scraping project. For python i use the berryconada distribution.
When I run my Spider, I get
ValueError: Unknown ECC curve
On my Laptop (Xubuntu 16.04) everything runs fine. Maybe I need to install an additional library or something?
Down below the full traceback.
Traceback (most recent call last):
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/python/failure.py", line 393, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/middleware.py", line 43, in process_request
defer.returnValue((yield download_func(request=request,spider=spider)))
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/utils/defer.py", line 45, in mustbe_deferred
result = f(*args, **kw)
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/handlers/__init__.py", line 65, in download_request
return handler.download_request(request, spider)
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/handlers/http11.py", line 63, in download_request
return agent.download_request(request)
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/handlers/http11.py", line 300, in download_request
method, to_bytes(url, encoding='ascii'), headers, bodyproducer)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/web/client.py", line 1633, in request
endpoint = self._getEndpoint(parsedURI)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/web/client.py", line 1617, in _getEndpoint
return self._endpointFactory.endpointForURI(uri)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/web/client.py", line 1494, in endpointForURI
uri.port)
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/contextfactory.py", line 59, in creatorForNetloc
return ScrapyClientTLSOptions(hostname.decode("ascii"), self.getContext())
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/contextfactory.py", line 56, in getContext
return self.getCertificateOptions().getContext()
File "/home/pi/berryconda3/lib/python3.6/site-packages/scrapy/core/downloader/contextfactory.py", line 51, in getCertificateOptions
acceptableCiphers=DEFAULT_CIPHERS)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/python/deprecate.py", line 792, in wrapped
return wrappee(*args, **kwargs)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 1595, in __init__
self._ecCurve = _OpenSSLECCurve(_defaultCurveName)
File "/home/pi/berryconda3/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 1744, in __init__
raise ValueError("Unknown ECC curve.")
I dropped berryconda and pip installed scrapy. If you're getting this error on Jessie, moving to Stretch gives you access to the newer openssl libs which contain the missing things.
After I upgraded to Stretch I cut berryconda from my path, pip uninstalled cryptography, twisted, pyopenssl, and scrapy.
Then with the no cache option I pip installed scrapy, which brought all those packages back, and now my spider is running.

Kazoo package using Jython

Kazoo's fairly working under the Python, but the project which i'm working on requires to use it under the Jython.
Here is the issue:
>>> from kazoo.client import KazooClient
>>> zk = KazooClient('127.0.0.1')
>>> zk.start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\jython2.7.0\Lib\site-packages\kazoo\client.py", line 541, in start
event = self.start_async()
File "C:\jython2.7.0\Lib\site-packages\kazoo\client.py", line 576, in start_async
self._connection.start()
File "C:\jython2.7.0\Lib\site-packages\kazoo\protocol\connection.py", line 170, in start
rw_sockets = self.handler.create_socket_pair()
File "C:\jython2.7.0\Lib\site-packages\kazoo\handlers\threading.py", line 165, in create_socket_pair
return utils.create_socket_pair(socket)
File "C:\jython2.7.0\Lib\site-packages\kazoo\handlers\utils.py", line 148, in create_socket_pair
temp_srv_sock.bind(('', port))
File "C:\jython2.7.0\Lib\_socket.py", line 1367, in meth
return getattr(self._sock,name)(*args)
File "C:\jython2.7.0\Lib\_socket.py", line 812, in bind
self.bind_addr = _get_jsockaddr(address, self.family, self.type, self.proto, AI_PASSIVE)
File "C:\jython2.7.0\Lib\_socket.py", line 1565, in _get_jsockaddr
addr = _get_jsockaddr2(address_object, family, sock_type, proto, flags)
File "C:\jython2.7.0\Lib\_socket.py", line 1594, in _get_jsockaddr2
hostname = {AF_INET: INADDR_ANY, AF_INET6: IN6ADDR_ANY_INIT}[family]
KeyError: 0
How i'd already said - there is no this kind issue using the python.
I'm pretty sure that it is connected with the Jython-version of the _socket.py file, but don't know the workaround.
What can you recommend?