I am having a bizarre problem in which Eclipse is raising an error for the source code of a python Lib package. I am using Python 3.7.1.
The relevant line is:
import urllib.request.urlopen as uReq
I don't believe the python interpreter I'm using is relevant to this particular problem. Nevertheless, here is the code for it. (I know, it's probably horrendous. If you know a better way to do this, please kindly point me in the right direction; this is my first time using jython and I'm sure it shows.)
interpreter = new PythonInterpreter();
interpreter.exec("import sys");
interpreter.exec("import os");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\src\\python')");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\Lib')");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\Lib\\site-packages')");
interpreter.exec("print(sys.path[0])");
interpreter.exec("from myscraper import validateUrl");
The error:
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\...\ThreadTracker\src\python\myscraper.py", line 6, in <module>
import urllib.request.urlopen as uReq
SyntaxError: ("mismatched input ',' expecting NAME",
('C:\\Users\\...\\ThreadTracker\\Lib\\urllib\\request.py', 140, 13, '
*, cafile=None, capath=None, cadefault=False, context=None):\n'))
Which seems to be having a problem with this line of code from the source file:
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
*, cafile=None, capath=None, cadefault=False, context=None):
I saw on another post that urllib3 could be used as well, so I tried:
from urllib3 import request as uReq
But this came up with its own error:
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Christina\ThreadTracker\src\python\myscraper.py", line 6, in <module>
from urllib3 import request as uReq
File "C:\Users\Christina\ThreadTracker\Lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\Christina\ThreadTracker\Lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
SyntaxError: ("no viable alternative at input '='", ('C:\\Users\\Christina\\ThreadTracker\\Lib\\logging\\__init__.py', 261, 55, ' method_name, "method:", err, file=sys.stderr)\n'))
I'm extremely confused as to why I'm getting errors from the source code... And I've been having a heck of a time just trying to get the java-python integration to work.
Related
Im getting this error when starting my software i dont know how to repair this
Traceback (most recent call last):
File "/root/findex/lib/python3.5/site-packages/findex_gui/main.py", line 208, in web
run_async()
File "/root/findex/lib/python3.5/site-packages/findex_gui/main.py", line 201, in run_async
from findex_gui.web import app
File "/root/findex/lib/python3.5/site-packages/findex_gui/web.py", line 41, in <module>
from findex_gui.orm.connect import Database
File "/root/findex/lib/python3.5/site-packages/findex_gui/orm/connect.py", line 12, in <module>
from findex_gui.orm.models import BASE
File "/root/findex/lib/python3.5/site-packages/findex_gui/orm/models.py", line 22, in <module>
from findex_common.utils import rand_str
ImportError: cannot import name 'rand_str'
I'm not familiar with the libraries in question, but it seems the maintainer renamed this function in 0.15.14 of findex-common here: development
This has been adjusted for in findex-gui on the master branch though it seems it has not seen a release. Here's the commit which fixes the import: Forgot what I was doing - Ill just push it all ¯_(ツ)_/¯
One short term fix would be to downgrade to findex-common==0.15.13 and perhaps follow up by raising an issue on either project since the change seems non-ideal.
I'm trying to use the following package: https://github.com/Anorov/cloudflare-scrape/blob/master/cfscrape/init.py
I have the following test file:
import cfscrape
import sys
import execjs
who = sys.argv[1]
scraper = cfscrape.create_scraper()
print scraper.get(who).content
Which is outputting the following error:
Traceback (most recent call last): File "test.py", line 1, in import cfscrape File "build/bdist.macosx-10.10-intel/egg/cfscrape/__init__.py", line 17, in EnvironmentError: Your Javascript runtime 'JavaScriptCore' is not supported due to security concerns. Please use Node.js, V8, or PyV8.
Can anyone point me in the right direction to change my JS_ENGINE from JavaScriptCore to NodeJs
System : XP, work with python 2.7
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import json
File "C:\Python27\ArcGIS10.1\lib\json\__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "C:\Python27\ArcGIS10.1\lib\json\decoder.py", line 7, in <module>
from json import scanner
ImportError: cannot import name scanner
Anyone can explain me how to manage this error please ???
this morning I haven't got this problem, but this afternoon my script won't work ((
I think this is caused by relative import path,
File "C:\Python27\ArcGIS10.1\lib\json\decoder.py", line 7,
from json import scanner
it's trying to import scanner from
C:\Python27\ArcGIS10.1\lib\json
I'm trying this simple code:
import requests
print requests.__file__
r = requests.get('https://github.com/timeline.json')
It works flawlessly on the command line when I type the lines one by one, but not whenen when I execute it as a script or in Sublime Text 2. Here's the stack trace:
C:\Python27\lib\site-packages\requests\__init__.pyc
Traceback (most recent call last):
File "C:\Users\Bruce\Desktop\http.py", line 1, in <module>
import requests
File "C:\Python27\lib\site-packages\requests\__init__.py", line 53, in <module>
from requests.packages.urllib3.contrib import pyopenssl
File "C:\Python27\lib\site-packages\requests\packages\__init__.py", line 3, in <module>
from . import urllib3
File "C:\Python27\lib\site-packages\requests\packages\urllib3\__init__.py", line 16, in <module>
from .connectionpool import (
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 15, in <module>
from http.client import HTTPConnection, HTTPException
File "C:\Users\Bruce\Desktop\http.py", line 3, in <module>
r = requests.get('https://github.com/timeline.json')
AttributeError: 'module' object has no attribute 'get'
[Finished in 0.2s with exit code 1]
Answers on 'Module object has no attribute 'get' Python error Requests? didn't help much.
Could this be some error in my ST2 Python build system? I tried removing all requests modules in case there were multiples of them by using pip and reinstalled them.
Edit After reading the stacktrace again, you can see that urllib3 tries to import something from the http module. Your file is called http.py and is thus imported instead of the expected one.
The actual error happens because of the circular nature of the import. Since requests hasn't finished importing completely yet. The get function in requests isn't defined yet when the http import reaches import requests again.
Note: You will also want to always guard your entry point with the if __name__ == '__main__' construct. This will often avoid nasty errors for unsuspecting future developers (including yourself).
I tried this example:
import cherrypy
class Root(object):
#cherrypy.expose
#cherrypy.tools.json_out()
def getrange(self, limit=4):
return list(range(int(limit)))
cherrypy.quickstart(Root())
when I run this, I get:
Traceback (most recent call last):
File "D:/Dev/BaronPOS/baronpos/Server/tester.py", line 1, in <module>
import cherrypy
File "C:\Python27\lib\site-packages\cherrypy\__init__.py", line 62, in <module>
from cherrypy._cpcompat import urljoin as _urljoin, urlencode as _urlencode
File "C:\Python27\lib\site-packages\cherrypy\_cpcompat.py", line 244, in <module>
json_decode = json.JSONDecoder().decode
AttributeError: 'module' object has no attribute 'JSONDecoder'
and I have absolutely no idea why. I have checked if the module is present and the class and both are. Please help!
OK, I figured it out.
I was using SimpleJSONRPCServer previously (http://www.freenet.org.nz/dojo/pyjson/) but decided to move to a more flexible REST compatible architecture.
Apparantly I left an artifact called json.py, which was causing this...