I'm able to run my Google App Engine webapp2 app using Python Tools for Visual Studio 2012 without issues after following this tutorial, and even step through the server initialization code, but I can't get it to break at get or post methods when the website is loaded, similar to what is shown in this video with the main() method. When I pause the debugger, it always ends up in the following infinite loop in wsgi_server.py:
def _loop_forever(self):
while True:
self._select()
def _select(self):
with self._lock:
fds = self._file_descriptors
fd_to_callback = self._file_descriptor_to_callback
if fds:
if _HAS_POLL:
# With 100 file descriptors, it is approximately 5x slower to
# recreate and reinitialize the Poll object on every call to _select
# rather reuse one. But the absolute cost of contruction,
# initialization and calling poll(0) is ~25us so code simplicity
# wins.
poll = select.poll()
for fd in fds:
poll.register(fd, select.POLLIN)
ready_file_descriptors = [fd for fd, _ in poll.poll(1)]
else:
ready_file_descriptors, _, _ = select.select(fds, [], [], 1)
for fd in ready_file_descriptors:
fd_to_callback[fd]()
else:
# select([], [], [], 1) is not supported on Windows.
time.sleep(1)
Is it possible to set breakpoints in a Google App Engine webapp2 app in PTVS, which are triggered when the page is loaded from localhost?
Edit: using cprcrack's settings, I was able to successfully run GAE, but when loading the main page I get the error
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3003, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2862, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 719, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1797, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1648, in ExecuteCGI
app_log_handler = app_logging.AppLogsHandler()
File "C:\Python\lib\logging\__init__.py", line 660, in __init__
_addHandlerRef(self)
File "C:\Python\lib\logging\__init__.py", line 639, in _addHandlerRef
_releaseLock()
File "C:\Python\lib\logging\__init__.py", line 224, in _releaseLock
_lock.release()
File "C:\Python\lib\threading.py", line 138, in release
self.__count = count = self.__count - 1
File "C:\Python\lib\threading.py", line 138, in release
self.__count = count = self.__count - 1
File "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_debugger.py", line 557, in trace_func
return self._events[event](frame, arg)
File "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_debugger.py", line 650, in handle_line
if filename == frame.f_code.co_filename or (not bound and filename_is_same(filename, frame.f_code.co_filename)):
File "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_debugger.py", line 341, in filename_is_same
import ntpath
File "C:\Python\lib\ntpath.py", line 8, in <module>
import os
File "C:\Python\lib\os.py", line 120, in <module>
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
ImportError: cannot import name curdir
Is this error occurring because I need to roll back to Python 2.5 to use the old dev_appserver?
UPDATE#2
gcloud preview deprecated
it's back to original method
UPDATE#1
gcloud preview (it's newer and simpler),
replace this:
General->Startup File:
C:\Program Files\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\gcloud\gcloud.py
Debug->Script Arguments:
preview app run app.yaml --python-startup-script "pydevd_startup.py" --max-module-instances="default:1"
all rest is the same as the original answer below:
ORIGINAL ANSWER:
A.) Create A File to Inject remote debugger
make a new python file "pydevd_startup.py"
insert this:
import json
import sys
if ':' not in config.version_id:
# The default server version_id does not contain ':'
sys.path.append("lib")
import ptvsd #ptvsd.settrace() equivalent
ptvsd.enable_attach(secret = 'joshua')
ptvsd.wait_for_attach()
Save it in your working directory of your app
for more info look at the pytool remote debuging docu I mentioned above
B.) Edit Project Settings in VS 2013
Now open your Project Settings in VS and enter this:
General->Startup File: C:\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py
General->Working Directory: .
Debug->Search Paths: C:\Cloud SDK\google-cloud-sdk\lib
Debug->Script Arguments: --python_startup_script=".\pydevd_startup.py" --automatic_restart=no --max_module_instances="default:1" ".\app.yaml"
You could probably also use . instead of <path-to-your-app> but I wanted to be safe.
C.) Run Debugger
With Ctrl+F5 you run the debugger, without debugging. This sound weird, but we are actually not debugging right now, just running the dev server which than starts our script to inject the debugger code and wait for our remote debugger to connect, which will happen in the next step
D.) Start Remote Debugger
DEBUG->Attach to Process <Ctrl+Alt+P>
Qualifier: tcp://joshua#localhost:5678 <ENTER>
joshua is your secret key. If you want to change it (and you should), you also have to change it in the pydevd_startup.py. See pytool reference for more info.
F.) Be really happy!
You now can remote debug your application locally (erm, weird). To test this you probably should use a breakpoint at the start of your own script.
If you have any question, please ask. In the end it seems really simple, but to get this going was rough. Especially because pytools said, they don't support it...
G.) Start Debugging for real!
Open http://localhost:8080 in a browser (or any other address you configure your app to use). Now it should invoke the breaking point. If you are done and reload the site, it starts all over again. If you really want to end debugging or change some code, you have to restart the server and attach again. Don't forget to close the terminal window with the server open (use <Crtl+C> )
This is a known issue with Google App Engine for Python: currently, debugging does not work on any debugger. See here, here and here.
There's a workaround, but I don't know about getting this working for python tools for vs. In theory it should be possible.
https://groups.google.com/forum/#!topicsearchin/google-appengine/Boa/google-appengine/-m00Qz4Vc7U
You'd probably need this guide to get it working:
https://docs.google.com/document/d/1CCSaRiIWCLgbD3OwmuKsRoHHDfBffbROWyVWWL0ZXN4/edit#heading=h.fj44xnkhr0gr
I'm using the old dev_appserver for debugging and it's working for me in an scenario similar to yours. I also got a bunch of exceptions but I was able to just skip all of them following the instructions on this link (I also had to add "exceptions" for some ValueError exceptions).
These are my project properties:
General tab:
Startup File: C:\Program Files (x86)\Google\google_appengine\old_dev_appserver.py
Working Directory: ./
Windows Application: (unchecked)
Interpreter: Python 2.7
Debug tab:
Search Paths: C:\Program Files (x86)\Google\google_appengine
Script Arguments: --use_sqlite ./
Interpreter Arguments: (blank)
Interpreter Path: C:\Python27\python.exe
When there is no need for breakpoints I run the project with DEBUG > Execute Project in Python Interactive. This way you don't get the unneeded console window.
Related
I was using python-jenkins wrapper to operate on jenkins from Python. I want to delete a build using server.delete_build command, but whenever I try to use this command:
import jenkins
def build_job(para_value):
server = jenkins.Jenkins('http://localhost:8080', username='username', password='password')
if not server.job_exists('job_name'):
server.create_job('job_name', jenkins.EMPTY_CONFIG_XML)
server.build_job('job_name', parameters={'para1': para_value})
def delete_build(jobID):
print(jobID)
server = jenkins.Jenkins('http://localhost:8080', username='username', password='password')
server.delete_build('job_name', jobID)
This is the error that I get:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 1415, in delete_build
self.jenkins_open(requests.Request('POST',
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 557, in jenkins_open
return self.jenkins_request(req, add_crumb, resolve_auth).text
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 573, in jenkins_request
self.maybe_add_crumb(req)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 379, in maybe_add_crumb
req.headers[self.crumb['crumbRequestField']] = self.crumb['crumb']
Can someone suggest any solution for this?
There is not much info or solutions regarding this error, so I changed the if condition in the __init__.py of Jenkins module.
Go to /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py (this address is for Mac users):
Do this:
Remove: if self.crumb:
Add: if self.crumb and isinstance(req.headers, dict):
This will make your code work.
This answer is inspired from: https://www.mail-archive.com/python-jenkins-developers#lists.launchpad.net/msg00597.html
Thu, 06 May 2021 13:49:05 Desmond Driver v2.3
Traceback (most recent call last):
File "/opt/schrodinger2021-1/internal/bin/desmond_driver.py", line 294, in <module>
main(sys.argv[1:])
File "/opt/schrodinger2021-1/internal/bin/desmond_driver.py", line 279, in main
driver_model = get_driver_model(option.destrier_flag, backend)(args,
File "/opt/schrodinger2021-1/internal/bin/drivermodel.py", line 426, in __init__
DriverModel.__init__(self, args, backend)
File "/opt/schrodinger2021-1/internal/bin/drivermodel.py", line 118, in __init__
self._config_cuda()
File "/opt/schrodinger2021-1/internal/bin/drivermodel.py", line 175, in _config_cuda
tmp_dir = fileutils.get_directory_path(fileutils.TEMP)
File "/opt/schrodinger2021-1/internal/lib/python3.8/site-packages/schrodinger/utils/fileutils.py", line 669, in get_directory_path
return mm.get_schrodinger_temp_dir()
**RuntimeError: could not get username from env**
Hi there, I tried to install a molecular dynamic package on collab called Desmond. The installation looks fine, even the -h flag shows a good return. but when I try to run some real job, there the error showed up saying could not get the username from env. Not sure what is going on, please help if you have any ideas, many thanks.
try this
import getpass
getpass.getuser()
The current user name will be returned by this.
eg
>>> import getpass
>>> print(getpass.getuser())
root
>>>
I just figured it out after two months!
The trick is, unlike a local computer or an HPC cluster, the way of cloud platform does not define the USER environment variable, yes, it is as simple as the error shows to some extent.
Just do: (take the Baidu AI studio as example)
echo “export USER=aistudio” >> ~/.bashrc
source ~/.bashrc
that’s it, and then, desmond will be able to up and running, I believe on Google Colab, the solution should be very similar.
The best way to find the correct USER value for your system is use "printenv" and look for the $HOME variable, your username should be as part of $HOME, then you just copy that name and give it to the new $USER variable.
I'm trying to run a test in a docker container, which runs locally with no issues:
I want to upload a correct.csv file from 'correct' directory
*** Keyword ***
Upload file
[Arguments] ${directory} ${file}
Choose File ${choose_file_input} ${EXECDIR}/Files/${directory}/${file}
** Test case ***
Upload
Upload file correct correct.csv
But when running test in docker I get a FAIL with the AttributeError: module 'base64' has no attribute 'encodestring'. Is it because there is no GUI in docker? or the encoding needs to be fixed? Or eventually maybe there is another solution I can use for uploading files?
15:20:01.250 INFO Sending /App/Files/correct/correct.csv to browser.
15:20:01.251 DEBUG POST http://192.168.1.29:4444/wd/hub/session/4b6d453b394adaaa51bb4149e9ba8678/elements {"using": "xpath", "value": "//div[#id=\"upload\"]//input"}
15:20:01.252 DEBUG Starting new HTTP connection (1): 192.168.1.29:4444
15:20:01.305 DEBUG http://192.168.1.29:4444 "POST /wd/hub/session/4b6d453b394adaaa51bb4149e9ba8678/elements HTTP/1.1" 200 90
15:20:01.305 DEBUG Finished Request
15:20:01.618 FAIL AttributeError: module 'base64' has no attribute 'encodestring'
15:20:01.619 DEBUG Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/SeleniumLibrary/__init__.py", line 490, in run_keyword
return DynamicCore.run_keyword(self, name, args, kwargs)
File "/usr/local/lib/python3.9/site-packages/robotlibcore.py", line 103, in run_keyword
return self.keywords[name](*args, **(kwargs or {}))
File "/usr/local/lib/python3.9/site-packages/SeleniumLibrary/keywords/formelement.py", line 224, in choose_file
self.find_element(locator).send_keys(file_path)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 475, in send_keys
value = self._upload(local_file)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 695, in _upload
content = base64.encodestring(fp.getvalue())
Based on the traceback you have found this issue:
Selenium 3 is incompatible with Python 3.9
This is the fix for the issue: DeprecationWarning of base64.encodestring().
They won't back port this fix:
Thanks for the issue. We won't be releasing another version 3 as we're
heading to finishing off Selenium 4. It is a drop in replacement to
use Selenium 4.0.0.a5 so should work the same. There should not be any
breaking changes.
So you could upgrade selenium to Selenium 4.0.0.a5 or
Downgrade Python to 3.7 for example. I suppose locally you do not run 3.9.
We were running into this issue as well, but going back to an older version of Python was not an option due to incompatibilities with other libraries. If you find yourself in the same spot, you can re-create the alias like so:
import base64
base64.encodestring = base64.encodebytes
In whatever your entry-point is.
I want to search a Perforce depot for files.
I do this from a python script and use the p4python library command:
list = p4.run("files", "//mypath/myfolder/*")
This works fine as long as myfolder contains some files. I get a python list as a return value. But when there is no file in myfolder the program stops running and no error message is displayed. My goal is to get an empty python list, so that I can see that this folder doesn't contain any files.
Does anybody has some ideas? I could not find information in the p4 files documentation and on StackOverflow.
I'm going to guess you've got an exception handler around that command execution that's eating the exception and exiting. I wrote a very simple test script and got this:
C:\Perforce\test>C:\users\samwise\AppData\local\programs\python\Python36-32\python files.py
Traceback (most recent call last):
File "files.py", line 6, in <module>
print(p4.run("files", "//depot/no such path/*"))
File "C:\users\samwise\AppData\local\programs\python\Python36-32\lib\site-packages\P4.py", line 611, in run
raise e
File "C:\users\samwise\AppData\local\programs\python\Python36-32\lib\site-packages\P4.py", line 605, in run
result = P4API.P4Adapter.run(self, *flatArgs)
P4.P4Exception: [P4#run] Errors during command execution( "p4 files //depot/no such path/*" )
[Error]: "//depot/no such path/* - must refer to client 'Samwise-dvcs-1509687817'."
Try something like this ?
import os
if len(os.listdir('//mypath/myfolder/') ) == 0: # Do not execute p4.run if directory is empty
list = []
else:
list = p4.run("files", "//mypath/myfolder/*")
I'm recently started to use python with mobile app automation, as i decided to use python, the main instruments that I've found were monkeyrunner and androidviewclient.
But there is the first issue with which i dont know what to do:
package = 'com.mypackage.android'
activity = '.launchActivity'
component = package + "/" + activity
device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component)
time.sleep(3)
vc = ViewClient(device, serialno)
vc.dump()
showMenu = vc.findViewById("id/no_id/8")
showMenu.touch()
as i'm running it in windows cmd - monkeyrunner mypath\test-case1.py
i receive an exception:
131213 18:42:32.555:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
131213 18:42:32.555:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "C:\Python27\tests\1.py", line 26, in <module>
device, serialno = ViewClient.connectToDeviceOrExit()
File "C:\Program Files (x86)\Android\AndroidViewClient\AndroidViewClient-maste
r\AndroidViewClient\src\com\dtmilano\android\viewclient.py", line 1381, in conne
ctToDeviceOrExit
ViewClient.setAlarm(timeout+5)
File "C:\Program Files (x86)\Android\AndroidViewClient\AndroidViewClient-maste
r\AndroidViewClient\src\com\dtmilano\android\viewclient.py", line 1341, in setAl
arm
signal.alarm(timeout)
File "C:\Program Files (x86)\Android\android-sdk\tools\lib\jython-standalone-2
.5.3.jar\Lib\signal.py", line 222, in alarm
NotImplementedError: alarm not implemented on this platform
am I doing something wrong? Please help.
Thank you a lot!
This is how setAlarm looks like
#staticmethod
def setAlarm(timeout):
osName = platform.system()
if osName.startswith('Windows'): # alarm is not implemented in Windows
return
signal.alarm(timeout)
so, it tries to identify that is Windows and then not invoking signal.alarm() which is not implemented, but for some reason it fails in your case.
Try to print the result of osName to see what went wrong.
UPDATE
Now I see, you are using monkeyrunner as the interpreter but AndroidViewClient >= 4.0.0 is 100% pure python, so you should run your scripts using a python 2.x interpreter.