I'm experiencing an issue with urlfetch. Seems that for the URL used in the code, follow_redirects=True works only locally.
Here's the code I used for testing:
def redirect_test():
url = 'http://0214.by/job.php?busy=ПОСТОЯННАЯ'
response = urlfetch.fetch(url, follow_redirects=True)
if 'location' in response.headers:
ret = 'redirect ignored. location: %s<br>' % response.headers['location']
url = urlparse.urljoin(url, response.headers['location'])
response = urlfetch.fetch(url, follow_redirects=False)
if 'location' in response.headers:
ret += 'redirect followed manually and another redirect response received'
else:
ret += 'redirect followed manually and no more redirects received'
else:
ret = 'redirect followed automatically'
return ret
The problem is that when I'm running this code locally I'm always getting the "Redirect followed automatically" message. When deployed on google app engine, the "Redirect followed manually and no more redirects received" message is always shown.
The URL returns a redirect to https page.
It makes me think the redirect is followed as expected only when running locally for some reason. I would appreciate any ideas on what this could be caused by.
Related
This is my first ever question.
I'm using react/vite and Rails 7 to build a firehouse management web app. I originally set up rails as an api with --api. Right now, I can log in but when the user clicks home, or any other link on the page, I loose the authorization(or thats what I'm thinking). I'm using the Bcrypt gem. The console.log(user) on my other pages is returning null, but on the inital login it returns the user object. Now, I have another issue with the logging in all together.
I'm getting a 422 'Unprocessable entity' where my request.base_url doesnt match the localhost:3000. I'm assuming thats because vite is running on 5173?
Here is the error
{status: 422, error: 'Unprocessable Entity', exception: '#<ActionController::InvalidAuthenticityToken: HTTP…t match request.base_url (http://localhost:3000)>', traces: {…}}
error
:
"Unprocessable Entity"
exception
:
"#<ActionController::InvalidAuthenticityToken: HTTP Origin header (http://127.0.0.1:5173) didn't match request.base_url (http://localhost:3000)>"
status
:
422
puma.rb
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
I tried to convert rails to the full framework because I thought it was something with the session and cookies. I added a cookie serializer and a session_store.
application.rb
class Application < Rails::Application
# Adding cookies and session middleware
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore
config.api_only = false
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
# This will allow any origin to make requests to any resource on your server, using any HTTP method.
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
methods: %i[get post put patch delete options head]
end
end
end
end
cookie_serializer.rb
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
session_store.rb
if Rails.env === 'production'
Rails.application.config.session_store :cookie_store, key: '_fire-sphere', domain: '_fire-sphere-json-api'
else
Rails.application.config.session_store :cookie_store, key: '_fire-sphere'
end
Here is my application_controller.rb
class ApplicationController < ActionController::Base
include ActionController::Cookies
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity
def authorized
return render json: {error: "Not Authorized"}, status: :unauthorized unless session.include? :current_user
end
private
def render_unprocessable_entity(invalid)
render json: {errors: invalid.record.errors.full_messages}, status: :unprocessable_entity
end
def render_not_found(error)
# byebug
render json: {error: "#{error.model} Not Found"}, status: :not_found
end
end
show method in users_controller.rb
def show
# using session to find user in question. sessions are in user browser
# if session for user currently happening, set our user to that user and render json
# byebug
current_user = User.find_by(id: session[:current_user])
render json: current_user
end
I think somehow the user isn't getting stored in the session. I was able to check the params on my initial problem and the user was in there but not when I navigated away. I think I've shnaged somthething somewhere and caused a whole other problem now. Thank you for taking a look! I hope it is something simple..
[header][1]
[header][2]
i am trying to send a get request to etherpad hosted in a different domain. the OPTIONS preflight request goes through but the get request returns 403 status.
however when i install CORS for chrome extension the request goes through
when i install cors chrome extension the request goes through
here is my code:
/* ........ export draft to html/pdf/word ........ */
//get content for this template
var url = Drafting.domain + Drafting.port + '/p/' + Drafting.padID + '/export/html?' + 'apikey=' + Drafting.apikey;
$http.get(url).then(function(response, status){
if(typeof(callback)==='function' && callback)
{
callback(response.data);
}
});
```}
[1]: https://i.stack.imgur.com/25dsj.png
[2]: https://i.stack.imgur.com/ivHnn.png
i just passed 'withCredentials:true' together with the url and then modified the importexport.js inside the etherpad files where 'AccessControlAllowOrigin' was set to '*' i replaced it with a specific domain and it worked.
function multipurpose_zymphonies_theme_preprocess_page(&$vars) {
$header = drupal_get_http_header("status");
if ($header == "404 Not Found") {
$vars['theme_hook_suggestions'][] = 'page__404';
}
elseif ($header == "403 Forbidden") {
$vars['theme_hook_suggestions'][] = 'page__403';
}
}
I am using this above code to redirect the 404 and 403 to custom pages
but
nothing happens. I have created two files: page--404.tpl.php and
page--403.tpl.php in my theme templates folder
if i simply write in the url "http://example.com/readme" then its show 404 which is custommize by me but when i write like "http://example.com/readme.txt" then its show
Not Found The requested URL "/readme.txt" was not found on this
server.
and for other error forbidden access when i write in the url like "http://example.com/%7C~.aspx"
Access forbidden! You don't have permission to access the requested
object. It is either read-protected or not readable by the server. If
you think this is a server error, please contact the webmaster. Error
403
I want to handle all these error for custom pages
You can configure default error pages through configuration from the url :
yoursite/admin/config/system/site-information
Administration > Configuration > System > Site information
I have two AppEngine modules, a default module running Python and "java" module running Java. I'm accessing the Java module from the default module using urlfetch. According to the AppEngine docs (cloud.google.com/appengine/docs/java/appidentity), I can verify in the Java module that the request originates from a module in the same app by checking the X-Appengine-Inbound-Appid header.
However, this header is not being set (in a production deployment). I use urlfetch in the Python module as follows:
hostname = modules.get_hostname(module="java")
hostname = hostname.replace('.', '-dot-', 2)
url = "http://%s/%s" % (hostname, "_ah/api/...")
result = urlfetch.fetch(url=url, follow_redirects=False, method=urlfetch.GET)
Note that I'm using the notation:
<version>-dot-<module>-dot-<app>.appspot.com
rather than the notation:
<version>.<module>.<app>.appspot.com
which for some reason results in a 404 response.
In the Java module I'm running a servlet filter which looks at all the request headers as follows:
Enumeration<String> headerNames = httpRequest.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
String headerValue = httpRequest.getHeader(headerName);
mLog.info("Header: " + headerName + " = " + headerValue);
}
AppEngine does set some headers, e.g. X-AppEngine-Country. But the X-Appengine-Inbound-Appid header is not set.
Why am I'm not seeing the documented behaviour? Any suggestions would be much appreciated.
Have a look at what I've been answered on Google groups, which led to an issue opened on the public issue tracker.
As suggested in the answer I received you can follow, for any update, the issue over there.
Getting the following error on Python AppEngine:
HTTPException: Deadline exceeded while waiting for HTTP response from URL: https://www.googleapis.com/books/v1/users/115429583296661000087/bookshelves/1001/volumes?maxResults=12&startIndex=0
URL is .json format, and im grabbing it via the following code on my application:
request = urllib2.Request(bookShelfUrl, None, {'Content-Type': 'application/json'})
bookShelfJsonRaw = urllib2.urlopen(request)
bookShelfJsonObject = json.load(bookShelfJsonRaw)
works fine when testing in localhost, only gives an error in production. it also worked fine in production up until today when it mysteriously started returning that error.
any thoughts?
I did not know was the issue solved by google or it start working right after i modify the code and specify timout parameter instead of deafults for http instantiation:
httplib2.Http(timeout=15)
The Google Books gData API was timing out because I wasn't passing in the country code. For whatever reason it worked fine without the country on a local test server but whenever I pushed it to production it would timeout. After adding country=US the json feed worked fine.
bookShelfUrl = 'https://www.googleapis.com/books/v1/users/' + \
bookShelfId + \
'/bookshelves/1001/volumes?' + \
'maxResults=' + str(maxResults) + \
'&startIndex=' + str(startIndex) + \
'&country=US'