Unable to import 'file-type' package - import

I downloaded this package from https://www.npmjs.com/package/file-type
And when I try to import it in my react App.js:
import {fileTypeFromFile} from 'file-type';
It gives the following error:
# ./node_modules/file-type/core.js 1661:12-33
# ./node_modules/file-type/browser.js 3:0-93 34:25-47 40:9-27 42:0-86 42:0-86 42:0-86 42:0-86
# ./src/App.js 10:0-45
# ./src/index.js 7:0-24 16:36-39
webpack 5.70.0 compiled with 2 errors and 2 warnings in 551 ms

Related

When execute the test script in appium it display AttributeError: can't set attribute

import time
import ScrollUtil
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Android'
desired_caps['appPackage'] = 'com.samsung.android.dialer'
desired_caps['appActivity'] = 'com.samsung.android.dialer.DialtactsActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
ScrollUtil.swipeUp(4,driver)
ScrollUtil.swipeDown(4,driver)
# driver.find_element_by_android_uiautomator(
# 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("Akash").instance(0))').click()
time.sleep(2)
driver.quit()
`
When I execute the above scripts I receive the below error messages and cannot be executed. I have already open the Appium Server
self.capabilities = response.get('value')
AttributeError: can't set attribute
Error message
Reinstall Appium-Python-Client using pip, instead of npm
And make sure selenium 3.XX version is installed

How to generate and include GRPC code in a packaged module

I need to generate python grpc code from protobuf files and include them as a packaged module for my project. This is my setup.py
from setuptools import setup, find_namespace_packages
import os
import sys
def generate_grpc():
from grpc_tools import protoc
import pkg_resources
inclusion_root = os.path.abspath("path-to-proto-files")
output_root = os.path.abspath("path-output")
proto_files = []
for root, _, files in os.walk(inclusion_root):
for filename in files:
if filename.endswith('.proto'):
proto_files.append(os.path.abspath(os.path.join(root,
filename)))
well_known_protos_include = pkg_resources.resource_filename(
'grpc_tools', '_proto')
for proto_file in proto_files:
command = [
'grpc_tools.protoc',
'--proto_path={}'.format(inclusion_root),
'--proto_path={}'.format(well_known_protos_include),
'--python_out={}'.format(output_root),
'--grpc_python_out={}'.format(output_root),
] + [proto_file]
if protoc.main(command) != 0:
sys.stderr.write('warning: {} failed'.format(command))
class BuildPyCommand(build_py):
def run(self):
generate_grpc()
build_py.run(self)
setup(cmdclass={
'build_py': BuildPyCommand,
},
setup_requires=[
'grpcio-tools',
],
package_dir={'': 'src'},
packages=find_namespace_packages(where='src')
)
I run this and see that the generated files are not copied to the build directory and as a result are not available when packaged.

Jython using pywinauto is throwing TypeError: __enter__(): expected 1 args; got 0 when trying to run it from java

I am trying to run a python script from java; in py script I am using pywinauto package and want to initiate notepad++.
When I am running this script it works fine, however when same is called from Java main method it throws TypeError: __enter__(): expected 1 args; got 0.
Below is python script:
import sys
sys.path.append("C:\\jython2.7.0\\bin")
sys.path.append("C:\\Python27")
sys.path.append("C:\\Python27\\Lib")
sys.path.append("C:\\jython2.7.0\\Lib")
def runpradeep():
print "trying to run it"
from pywinauto.application import Application
app = Application().start('C:\\Program Files (x86)\\Notepad++\\notepad++.exe')
app.kill()
runpradeep()
and below is java class:
package himalaya;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.Properties;
public class OpenBoApplication {
public static void main(String[] args) throws ScriptException {
Properties props = new Properties();
props.put("python.home", "C:\\Python27");
props.put("python.console.encoding", "UTF-8");
props.put("python.security.respectJavaAccessibility", "false");
props.put("python.import.site", "false");
Properties preprops = System.getProperties();
PythonInterpreter.initialize(preprops, props, new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("D:path to py script\\renatoplease.py");
interpreter.exec("runpradeep()");
}
}
Below is error log:
Exception in thread "main" Traceback (most recent call last):
File "D:\pbhardwa\IdeaProjects\javapythongroovy\src\com\ingenico\runmiddleware\renatoplease.py", line 16, in
runpradeep()
File "D:\pbhardwa\IdeaProjects\javapythongroovy\src\com\ingenico\runmiddleware\renatoplease.py", line 11, in runpradeep
from pywinauto.application import Application
File "pyclasspath/pywinauto/application.py", line 72, in
File "C:\Python27\Lib\multiprocessing__init__.py", line 65, in
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "C:\Python27\Lib\multiprocessing\util.py", line 39, in
import threading # we want threading to install it's
File "C:\Python27\Lib\threading.py", line 1191, in
_shutdown = _MainThread()._exitfunc
File "C:\Python27\Lib\threading.py", line 1083, in init
self._Thread__started.set()
File "C:\Python27\Lib\threading.py", line 582, in set
"""
File "C:\Python27\Lib\threading.py", line 286, in enter
return self.lock.__enter()
TypeError: enter(): expected 1 args; got 0
I am using Intellij ultimate edition and Pycharm plugin is installed. I have also installed pywinauto(as mentioned enter link description here), pythonpath is also set. Also added jython dependencies to class path. Attaching complete project
Any help will surely help us.

environment variables using subprocess.check_output Python

I'm trying to do some basic module setups on my server using Python. Its a bit difficult as I have no access to the internet.
This is my code
import sys
import os
from subprocess import CalledProcessError, STDOUT, check_output
def run_in_path(command, dir_path, env_var=''):
env_var = os.environ["PATH"] = os.environ["PATH"] + env_var
print(env_var)
try:
p = check_output(command, cwd=dir_path, stderr=STDOUT)
except CalledProcessError as e:
sys.stderr.write(e.output.decode("utf-8"))
sys.stderr.flush()
return e.returncode
else:
return 0
def main():
requests_install = run_in_path('python setup.py build',
'D:\installed_software\python modules\kennethreitz-requests-e95e173')
SQL_install = run_in_path('python setup.py install', # install SQL module pypyodbc
'D:\installed_software\python modules\pypyodbc-1.3.3\pypyodbc-1.3.3')
setup_tools = run_in_path('python setup.py install', # install setup tools
'D:\installed_software\python modules\setuptools-17.1.1')
psycopg2 = run_in_path('easy_install psycopg2-2.6.1.win-amd64-py3.3-pg9.4.4-release', # install setup tools
'D:\installed_software\python modules', ';C:\srv_apps\Python33\Scripts\easy_install.exe')
print('setup complete')
if __name__ == "__main__":
sys.exit(main())
now it gets tricky when i start trying to use easy install. It appears my env variables are not being used by my subprocess.check_output call
File "C:\srv_apps\Python33\lib\subprocess.py", line 1110, in _execute_child
raise WindowsError(*e.args)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I don't want to have to upgrade to 3.4 where easy install is installed by default because my other modules are not supported on 3.4. My main challenge is the subprocess.check_call method does not take environment variables as an input and im wary of trying to use Popen() as I have never really got it to work successfully in the past. Any help would be greatly appreciated.
PATH should contain directories e.g., r'C:\Python33\Scripts', not files such as: r'C:\Python33\Scripts\easy_install.exe'
Don't hardcode utf-8 for an arbitrary command, you could enable text mode using universal_newlines parameter (not tested):
#!/usr/bin/env python3
import locale
import sys
from subprocess import CalledProcessError, STDOUT, check_output
def run(command, *, cwd=None, env=None):
try:
ignored = check_output(command, cwd=cwd, env=env,
stderr=STDOUT,
universal_newlines=True)
except CalledProcessError as e:
sys.stderr.write(e.output)
sys.stderr.flush()
return e.returncode
else:
return 0
Example:
import os
path_var = os.pathsep.join(os.environ.get('PATH', os.defpath), some_dir)
env = dict(os.environ, PATH=path_var)
run("some_command", cwd=some_path, env=env)
run("another_command", cwd=another_path, env=env)

Selenium find_element_by_id returns None

I am using selenium and i have properly installed the selenium module on redhat linux 6.
Below is my script:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import zlib
class Sele1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://bugzilla.example.com/"
self.verificationErrors = []
def test_sele1(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("Bugzilla_login").clear()
driver.find_element_by_id("Bugzilla_login").send_keys("username")
driver.find_element_by_id("Bugzilla_password").clear()
driver.find_element_by_id("Bugzilla_password").send_keys("password")
driver.find_element_by_id("log_in").click()
driver.find_element_by_id("quicksearch").clear()
driver.find_element_by_id("quicksearch").send_keys("new bugs is bugzilla tool")
driver.find_element_by_xpath("//input[#value='Find Bugs']").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
When i am running this script it is showing errors:
ERROR: test_sele1 (main.Sele1)
Traceback (most recent call last):
File "sele1.py", line 19, in test_sele1
driver.find_element_by_id("Bugzilla_login").clear()
AttributeError: 'NoneType' object has no attribute 'clear'
Ran 1 test in 2.018s
FAILED (errors=1)
Plateform: Redhat
Python Version: 2.6
Note: while running the same script in windows7, it is running fine but not running in linux with python2.6
Please help me for this...
Thanks in advance!
Simple: Selenium can't find an element called "Bugzilla_login".
There could be hundreds of reasons this may be happening. I'd start with checking whether you're loading the correct page.