I developed a webapp using Django framework and hosted it on Digital Ocean. The server is supposed to receive a Json from a client written using Ruby rails framework.
The Django app cannot see the Json and so I want use django-cors-headers https://github.com/ottoyiu/django-cors-headers which require me to install django-cors-headers, but I have already hosted the app (i.e. the server).
My questions are ( sorry I am newbie)
Is it possible to install django-cors-headers using the pip install django-cors-headers on the server host computer at Digital Ocean using may be PUTTY or Winscp? If yes, pls how do i do it?
Did I choose the right solution to my problem?
Below is the code for the server (views.py) and I am using Django 1.9 and python 2.7.6
from django.shortcuts import render
from django.http import HttpResponse
from django.http import JsonResponse
import json
def qucserver (request):
if request.method == 'POST':
print request.body
jsdata = json.loads(request.body)
reply = {"data": jsdata}
return JsonResponse ( reply )
else:
message = 'You submitted an empty form.'
reply = {"Error": message}
return JsonResponse (reply)
The output is always
{data: "json = JSON_DATA"}
If you have shell access you certainly ought to be able to install the django-cors-headers app or any other app using pip. However if your virtualenv is read only, you can simply copy the files from django-cors-headers into your project.
Related
I have a simple GET API. When I click "Try it out" and then "Execute" in Swagger UI, I can see the request reaching the server and getting processed successfully with HTTP status code 200 - ascertained by looking into the server logs.
I would like to see the response body in Swagger UI. What addition or change needs to be done to the OpenAPI YAML spec? I'm using OpenAPI 3.0.3.
By enabling CORS in my flask app, I have managed to overcome the issue ...
From shell prompt ...
pip install -U flask-cors
Inside app.py ...
...
from flask_cors import CORS
...
app = Flask(__name__)
CORS(app)
...
I want to fetch some data in Bazel over HTTP. There's a http_file method that looks like what I want. The remote server I'm fetching from uses authentication, so I've written it as
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = "data_file",
urls = ["https://example.com/data.0.1.2"],
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
downloaded_file_path = "data_file",
)
When I try the build, I get
WARNING: Download from https://example.com/data.0.1.2 failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 401 Unauthorized
Followed by fatal errors because the file doesn't exist.
The error makes me think that I'm not authenticating correctly. I have a .netrc file and curl is able to use it to fetch the file.
Is there a way for me to debug? If it was curl, I would pass -v and see the auth header being sent with the request. I'm not sure if bazel is failing to send any authentication or if it's incorrect.
Running Bazel 3.2.0 on Mac OS (Darwin 19.6.0) and on Linux (Ubuntu 18.04).
HTTP 401 indeed sounds like incorrectly or not at all authenticated. .netrc should be supported and recognized. If not explicitly specified with netrc attribute, ${HOME}/.netrc would be tried if HOME is in the environment and bazel runs on non-Windows host (this has been the case since bazel 1.1; and shortly in 0.29) or %USERPROFILE%/.netrc if the variable is in the environment and running on Windows (this has been the case since 3.1). At the risk of stating the obvious, the .netrc should be owned by the same UID under which the process using it runs and its permbits should be 0600. If authentication methods other then http basic are needed, auth_patterns attribute needs to be used to configure that.
I am not aware of there being any ready made repository rule debugging facility such as CLI flag, but in this case it should be viable to copy the implementation of of the rule and functions it uses from tools/build_defs/repo, instrument it to get debugging info from it and use that for the purpose. For starters perhaps just print(auth) of what auth = _get_auth(ctx, all_urls) yielded to see if the that rule got the right idea about how to talk to host in question. It should be a dict with type, login, password information for each individual urls entries. The magic itself happens in use_netrc.
I have been installing google assistant to my windows 10 laptop, reading about it on different stackoverflow forums and on its website couldn't get it to work but then I tried this one youtube video
I got everything to work but at the end when I want to test the google assistant I get error (which I read about on here also but couldn't solve it) this is what I wrote on cmd :
python -m googlesamples.assistant
and this is error I got :
C:\Users\kalle\AppData\Local\Programs\Python\Python37\python.exe: No
module named googlesamples.assistant.main;
'googlesamples.assistant' is a package and cannot be directly
executed---
I have got Project ID and Model Id in case you ask to create.
You can't call python -m googlesamples.assistant. That's not a script, it's basically a directory. You probably want to run python -m googlesamples.assistant.grpc.pushtotalk.
I am following the Neo4django manual: http://neo4django.readthedocs.org/en/latest/auth.html
and trying to setup Admin's interface. I am working under Mac OS X.
Before I started setting up this interface, I had my server running and everything worked. After I made the indicated changes, the server stopped with the error: Error: No module named contenttypes.
If I disable the contettypes line, I get the error Error: No module named admin.
In my settings.py file:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'polls',
'mysite',
'neo4django.admin',
'neo4django.contenttypes',
)
In urls.py:
from django.conf.urls import patterns, include, url
from neo4django import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)
In admin.py:
from neo4django import admin
from .models import Person
class PersonAdmin(admin.ModelAdmin):
pass
admin.site.register(Person, PersonAdmin)
Could please someone give me correct instructions for setting up the admin's page?
I suggest you throw away the entire tutorial for the moment and install neo4django with pip install -e git+https://github.com/scholrly/neo4django/#egg=neo4django. Also check the github https://github.com/scholrly/neo4django and when installing Django, don't install the latest version but the 1.5.4 version with pip install django==1.5.4
Also, install the 1.9.4 version of neo4j and not the 2.0 version.
If for any reason you find neo4django a bit complicated or not mature enough then you can try the py2neo library (not an ORM) or neomodel (https://github.com/robinedwards/neomodel)
We recently were able to get a small redhat server to experiment with shiny-server. Our IT department got shiny-server running and installed the Oracle client but I can't get ROracle to work in shiny-server. They (IT) have decided that it is an application issue and are starting to give up...
Initially ROracle didn't work on the server at all but we got it working from my user account by setting the LD_LIBRARY_PATH in my .bashrc file. With that done I can log into the server, and query the database from R. I can even use runApp() to run my shiny app from R.
When I try to access that same app through shiny-server I get the following error:
Listening on port 40679
Loading required package: DBI
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/lib64/R/library/ROracle/libs/ROracle.so':
libclntsh.so.11.1: cannot open shared object file: No such file or directory
Error : package or namespace load failed for 'ROracle'
Error : package or namespace load failed for 'ROracle'
which is the same error I was getting on my account before I set the LD_LIBRARY_PATH variable. The server is running as user shiny but apparently won't run any startup scripts so what fixed it for my user won't fix it for the shiny user. This is all very far outside my area of knowledge and as I said, our IT department says they are out of ideas.
I don't have sudo access to the server so the things I can try are limited. I tried setting the LD_LIBRARY_PATH from my server.R script before loading ROracle with Sys.setenv() and by using system() but those didn't work. Our DBA that has been trying to help me tried setting the LD_LIBRARY_PATH in /etc/init/shiny-server.conf but that doesn't seem to work either.
I am really hoping that someone here has some ideas.
Thanks
After a couple of frustrating days I found the solution. You need to set the LD_LIBRARY_PATH variable in the upstart script located at /etc/init/shiny-server.conf, but per the upstart documentation, you need to define it with the env keyword. So adding:
env LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib:$LD_LIBRARY_PATH
to beginning of the shiny-server.conf script seems to have fixed the problem.
Here's my blog post (about a year old) with a detailed description on how to get R Studio Server going with Oracle. LD_LIBRARY_PATH, OCI Lib and all the stuff is provided. Maybe this helps someone else: http://learnfrominfo.tumblr.com/post/38382388429/connect-r-studio-server-to-an-oracle-database-with
I had the same problem with PHP and Apache.
Please refer to the Setting the Oracle Environment in the PHP documentation.
Also, see comment - which syntax did you use in /etc/init/shiny-server.conf?
SERVER.R
library
library(RMySQL)
library(caTools)
library(rpart)
library(RJDBC)
shinyServer(
function(input ,output)
{
dvr =JDBC("oracle.jdbc.OracleDriver",classPath="D:/ojdbc6.jar")
url = ""
user = ""
password = ""
jd =dbConnect(dvr,url, user, password)
a1 <- eventReactive(input$predict,
{
a<-input$ref
table2<-data.frame(dbGetQuery(jd,paste0("
select colnames from Tablename where REFNO=",a," and ROWNUM<15
")))
print(table2)
print(bs<-table2)
}
)
output$dis<-renderTable({
a1()
})
}
)